给定一个如下所示的 Ruby on Rails 模型 (db/schema.rb):
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.string "other"
end
在users_controller.rb我正在做的事情中:
def new
@user = User.new
@user.email.downcase!
@user.other = "TEST"
end
在show视图 ( show.html.haml) 中:
User details:
%b #{@user.name} + #{@user.email} + #{@user.other}
问题是@user.other根本不显示该值。我的猜测是@user.otheris nil,但我不知道为什么它没有设置为TEST,因为我在new控制器操作中设置了它。
在我的Users模型中,我设置:
attr_accessible :name, :email, :other
有任何想法吗?
谢谢!