2016-07-07 65 views
-1

我有一個錯誤,當我運行下面的代碼:開發工作,但不是在生產中

::的ActionView ::模板錯誤(未定義的方法`total__quantity」的零:NilClass):

error : 

undefined方法`total__quantity'爲零:NilClass

+1

看起來好像「@ orgs」不包含您正在查找的元素。 – ehannes

回答

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

他的問題不是他的'child'是'nil',而不是'total_quantity'返回'nil'。它說'未定義的方法...用於'NilClass'; 'child'是'NilClass',對吧? – ehannes

+0

這是問題的一部分。我的問題是爲什麼孩子被從另一個收藏中重新分配,因爲「org」和「@ orgs」顯然不同。 – Okomikeruko

+0

是的。我試過了。但仍然以錯誤結束..你可以請看看我的新帖子,其中包括完整的代碼,並幫助我。 – kritzzzzot

0

這是因爲@org沒有孩子。你最好這樣做;

children = @org.children 

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

希望這會有所幫助。

+0

嗨@cabolanoz ..你可以看到我的新帖子,我包括我的完整代碼,並幫助我在這一個。 – kritzzzzot

相關問題