我是 RoR 的新手。我的问题是关于更新关联的活动模型的属性。
class User
has_many :toys
end
class Toy
belongs_to :user
end
我有一个用户形式的页面,我可以在其中更新用户的属性,以及关联的 user_devices 的某些属性:
<%= f.text_field :age %> # from user
<%= f.text_field :email %> # from user
....
<%= f.check_box :is_new %> # from toy!!
当我使用 update_attributes() 发布表单并更新所有属性时,它显示“ActiveModel::MassAssignmentSecurity::Error”
@user.update_attributes(params[:user]) # it gives ActiveModel::MassAssignmentSecurity::Error
另一个问题是,我不知道如何命名玩具表中的“is_new”属性。它应该是:toys_is_new 吗?
我也希望更新相关玩具的属性。你能帮我解决这个问题吗?