views:

93

answers:

1

Using Ruby on Rails, I have created a blog. The blog has posts, and comments associated with each post.

I want to add a name field to the comment controller (or model, not sure), so that the commenter is identified. Since right now it's just a comment that's being added. The name field should be stored in the database.

What is the best way to accomplish this, once I already have things set up and I just want to modify? Can scaffold or generate be used at this point? If so, how?

+2  A: 

You want to create a database migration file that adds a column to the Comments table in your database. You'll need to adjust your views to display a form field for the commenters name and for the blog to display the name along side the comment. This RoR Guide should get you started http://guides.rubyonrails.org/migrations.html

You can use Generate to do something like this

ruby script/generate migration AddCommentNames

And then edit the migration file that appears in db/migrations to add something along the lines of

add_column :comments, :name, :string
Scott