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.
这里的目标是检查用户是否正在提交任何具有已存在的bar属性的foos。我为模糊而道歉,但这是我能做的最好的事情。
1 个解决方案
#1
3
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?
如果你的一个foos(旧的或新的)没有任何条形...然后你打电话给它(或任何?)...你将在一个零对象上调用每个。这可能是个问题。但是一个行号肯定会有所帮助。你能获得完整的堆栈跟踪吗?
#1
3
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?
如果你的一个foos(旧的或新的)没有任何条形...然后你打电话给它(或任何?)...你将在一个零对象上调用每个。这可能是个问题。但是一个行号肯定会有所帮助。你能获得完整的堆栈跟踪吗?