开发工作,但不在生产中

问题描述 投票:0回答:2

运行以下代码时出现错误:

ActionView :: Template :: Error(nil:NilClass的未定义方法“ total__quantity”):

error :

nil:NilClass的未定义方法`total__quantity'

html ruby-on-rails haml
2个回答
0
投票

你有没有尝试过?

@org.children.each do |child|
  if (!child.total_quantity.nil?)
    %tr
      %td.child= link_to child.shrt_name, child

我假设在您的原始帖子中,您不小心在org.children.each之前省略了@

我也不确定为什么您会觉得需要在循环中重新分配child的价值。


0
投票

发生这种情况是因为@org没有孩子。 你最好这样做;

children = @org.children

unless children.empty?
   children.each do |child|
      if child.total_quantity > 0
         # Your code here
      end
   end
end

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.