Reputation: 11
I have an error when I run the below code:
ActionView::Template::Error (undefined method `total__quantity' for nil:NilClass):
error :
undefined method `total__quantity' for nil:NilClass
Upvotes: 0
Views: 57
Reputation: 294
It happens because @org
has no children. You better do this;
children = @org.children
unless children.empty?
children.each do |child|
if child.total_quantity > 0
# Your code here
end
end
end
Hope this helps.
Upvotes: 0
Reputation: 1183
Have you tried?
@org.children.each do |child|
if (!child.total_quantity.nil?)
%tr
%td.child= link_to child.shrt_name, child
I'm assuming that from your original post, you're accidentally omitting the @
before org.children.each
I'm also not sure why you feel the need to reassign the value of child
in your loop.
Upvotes: 0