0

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 assigning 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

Screenshot

ahmet
  • 4,955
  • 11
  • 39
  • 64
  • You ruby interpreter should also be generating a line number on which this nil is happening. That should tell you what object is getting set to nil (and hence, where the problem is, and on which form element). Please post that section of code as well. – jefflunt Jul 20 '11 at 13:02
  • Hard to say what's going on without your code... – Jeff Paquette Jul 20 '11 at 13:03

1 Answers1

1

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

Anatoly
  • 15,298
  • 5
  • 53
  • 77