I have multiple check boxes from a many to many relationship, And i'm trying to validate them so that none of the fields need a value to continue. At the moment if i try to create a user without as开发者_如何学Csigning them to a group/role through the checkboxes i get
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Also when a group is assigned but all other fields are left empty i still get the above error.
When everything has a value it works perfectly.
Form below
use the empty array if all checkboxes unchecked
params[:user][:group_ids] ||= []
if you still have the issue, you need to copy-paste your controller code here
精彩评论