How to use the Rails templates
Rails has a templating framework (is that the right word?) to easy allow you to add new components (is that the right word?) to your Rails project.
You can see a list of available options by entering rails generate in the terminal.
$ rails generate
Usage: rails generate GENERATOR [args] [options]
Generate a controller
For example, say you wanted to generate a Controller called Cows with an action of moo. you would enter:
$ rails generate controller Cows moo
Rails would then create the following:
route get "cows/moo"
If you are using Rspec for tests, just add --not-test-framework to the generate command to avoid creating normal tests
$ rails generate controller Cows moo --no-test-framework
Generate a Model
You can also generate Models from templates.
For example, say you want to generate a model to represent Farmers with two attributes, their name and their address.
$ rails generate model Farmer name:string address:string
Rails would generate the following:
$ rails generate model Farmer name:string email:string invoke active_record create db/migrate/[timestamp]_create_farmers.rb create app/models/farmer.rb invoke rspec create spec/models/farmer_spec.rb
The migration file (db/migrate/[timestamp]_create_farmers.rb) is a short Ruby program that creates a new Farmers table with the relevant attributes. To run this file and create the table in the DB enter:
$ rake db:migrate
For more information on templating see http://guides.rubyonrails.org/command_line.html#rails-generate