I'm new to RoR. My question is about updating associated Active Model's attr.
class User
has_many :toys
end
class Toy
belongs_to :user
end
and I have a page with a form of user where I can update user's attributes, and also certain attributes of associated user_devices:
<%= f.text_field :age %> # from user
<%= f.text_field :email %> # from user
....
<%= f.check_box :is_new %> # from toy!!
When I post the form and update all the attributes using update_attributes(), it shows "ActiveModel::MassAssignmentSecurity::Error"
@user.update_attributes(params[:user]) # it gives ActiveModel::MassAssignmentSecurity::Error
Another problem is, I don't know how to name the "is_new" attribute as it's in toy table.. Should it be :toys_is_new?
I want the associated toy's attributes to be updated as well. Can you help me with this?
Because
is_new?
is fromToy
, you have to useaccepts_nested_attributes_for
:To get this to work in the
view
, you'll need to use thefields_for
helper: