Adding a Model in Ruby on Rails

for Rails 2.*
Not for Rails 3

How to add a model in rails

  • ./script/generate resource MODELNAME
  • [ruby]./script/generate resource article[/ruby]

  • edit migrate file
  • edit model.rb – to add associations and validations
  • edit controller.rb – add the 7 rest methods
  • rake db:migrate – to run the new migration
  • If you have to add a table (like a join table) you can do something like, for example
  • [ruby]./script/generate migration add_join_table_for_articles_and_authors[/ruby]

Update to the routes file should be taken care of by generate resource, but might want to check).