how do i define a method in rails
I have generated scaffold for a author and I want to add an email address to the table. I have added author.email in my tags and it wants me to define a method. what method should i define for email and where? is it in the au开发者_如何学编程thors controller.
thanks
In your case email
is a field for the author
. You should add it to your database migration, rerun the rake db:migrare
and it'll be accessible as author.email
Also, make sure to add :email
to the attr_accessible
list in your author
model.
I think you got it incorrectly. As i believe you receiving error call " undefined method or variable call email" isn't it?? If so that means you need to add email field to the database table table you can do that by following commands
ruby script/generate migration AddEmailToAuthor email:string
rake db:migrate
now you can run your program
精彩评论