运行以下代码时出现错误:
ActionView :: Template :: Error(nil:NilClass的未定义方法“ total__quantity”):
error :
nil:NilClass的未定义方法`total__quantity'
你有没有尝试过?
@org.children.each do |child|
if (!child.total_quantity.nil?)
%tr
%td.child= link_to child.shrt_name, child
我假设在您的原始帖子中,您不小心在org.children.each
之前省略了@
我也不确定为什么您会觉得需要在循环中重新分配child
的价值。
发生这种情况是因为@org
没有孩子。 你最好这样做;
children = @org.children
unless children.empty?
children.each do |child|
if child.total_quantity > 0
# Your code here
end
end
end
希望这可以帮助。