Let’s say I forgot to add a field to my model. How do I go about adding it cleanly? Do I need to re-run rails generate or can I edit a file somewhere?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Either you should re-run your generate scaffold/model (will blow away existing code)
or you can add the field directly to the database and your view
Rails3:
rails generate migration add_column_name_to_table_name column_name:string
or
Rails2.x:
ruby script/generate migration addColumnToTableName column_name:string
which will generate a file in db/migrate which you can apply with a ‘rake db:migrate’
Then you should modify your views to add the appropriate code to display/edit the new field.
more info: http://railscasts.com/episodes/83-migrations-in-rails-2-0