Nested Object w/ Checkboxes - mass-assignment even with accepts_nested_attributes_for?

人走茶凉 提交于 2019-12-03 04:06:53

it sounds like this attribute isn't marked as safe for updating. You should be able to fix it by adding the following to your model class:

attr_accessible :roles

or possibly:

attr_accessible :roles_attributes

If you look, you may already have an attr_accessible call you can add this to. For more information this is documented here:

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002226

If you correct the spelling of attributes in your check_box_tag, it looks like it should work.

<% for role in Role.all %>
 <%= check_box_tag( "user[roles_attributes][id]",role.id) %>
 <%= role.rolename %>
 <br/>
<% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!