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
  • ./script/generate resource article
  • 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
  • ./script/generate migration add_join_table_for_articles_and_authors

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This Blog will give regular Commentators DoFollow Status. Implemented from IT Blögg