Rails - Accepts_nested_attributes_for mass assignment error

允我心安 提交于 2019-12-04 14:14:33

This might be the problem... from the API docs:

Using with attr_accessible

The use of attr_accessible can interfere with nested attributes if you’re not careful. For example, if the Member model above was using attr_accessible like this:

attr_accessible :name

You would need to modify it to look like this:

attr_accessible :name, :posts_attributes

http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#label-Using+with+attr_accessible

I got to the answer here eventually. The key was this line:

<%= collection_select(:customer, :customer_type_id, CustomerType.all, :id, :value, {}, {:class => "chzn-select"}) %>

which needed to be changed to:

<%= customer.collection_select(:customer_type_id, CustomerType.all, :id, :value, {}, {:class => "chzn-select"}) %>

Once this was changed, everything fell into place.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!