开发者

Validating HABTM Checkbox's

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

Validating HABTM Checkbox's


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜