Rails Conventions

Overview

  • Models are singular
  • Views and Controllers are plural

ControllersModels

Generate a new field for an existing model

rails g model [model name - singular] fieldname:fieldtype fieldname2:field type
Available field types
:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date,
        :binary, :boolean, :references

Generate a new field for an existing model

The safest way to add fields to an existing model is to just create a new migration:

rails g migration add_public_and_private_to_document public:string private:string
        

If you use the add_[column_names]to[model]naming convention, rails will work out the appropriate table and create the migration you want.

Have a read here for more info: http://guides.rubyonrails.org/migrations.html

Generate a model with extra description (i.e. precision)

Reference link
For Mac OS X 10.9

rails generate scaffold LineItem name price:decimal{8.2}

Deleting Tables

drop_table :table_name

Migrating database changes

Setting up the database on first install

bundle exec rake db:setup

This will run the rake db:schema:load which is more efficient then running a rake db:migrate on install
Run the migration scripts

bundle exec rake db:migrate

Reset the database and reload the database schema

bundle exec rake db:reset

Setting up the database for testing

bundle exec rake db:test:prepare

Opinions about People, Process and Technology

Optimization WordPress Plugins & Solutions by W3 EDGE