views:

130

answers:

1

I'm getting the error:

wrong argument type nil (expected Data)

Here's my code (names have been changed to protect the innocent ;) ):

old_foos.each do |foo|
  foo.bars.each do |old_bar|
    if new_foo.bars.any? {|new_bar| new_bar.name == old_bar.name} #assume new_foo is properly set
       check = 1
    end
  end
end
if check == 1
  do_something!
end

I have a nagging suspicion that this is a scope issue, but I'm not sure. Any pointers would be greatly appreciated. Thanks!

The goal here is to check if a user is submitting any foos that have a bar property that already exists. I apologize for the vagueness, but this is the best I can do.

+2  A: 

If one of your foos (old or new) doesn't have any bars... and then you call each (or any?) on it... you'll be calling each on a nil object. That may be the issue. But a line-number would certainly help. Can you get a full stacktrace?

Taryn East