开发者

how do i define a method in rails

开发者 https://www.devze.com 2023-03-01 22:45 出处:网络
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 a

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

0

精彩评论

暂无评论...
验证码 换一张
取 消