2014-01-08 31 views
0

錯誤發生在這條線:未定義的方法'>」爲無:NilClass

<p><small><%= time_ago_in_words(comment.created_at) %> ago</small></p> 

爲什麼會發生,以及如何解決呢?

我很抱歉缺乏提供的代碼。只是不知道該給你們什麼。

+0

你確定'comment.created_at'不是零嗎? – user2503775

+0

沒有。這不是零。 '=>週三,2014年1月08日15:22:13 UTC +00:00' @ user2503775 –

回答

1

快速瀏覽了time_ago_in_words的代碼,並看到它在distance_of_time_in_words中稱爲方法>

它可能會返回錯誤,因爲您提供的參數comment.created_at正在返回nil。然後將這個nil與另一個值比較,這就是爲什麼你會得到這個錯誤。請確保你不要做一個零有條件像提供nil ARG到time_ago_in_words

<% if comment.created_at %> 
    <p><small><%= time_ago_in_words(comment.created_at) %> ago</small></p> 
<% end %> 

希望幫助!

+0

美麗。來自各個角度的美麗。 –

+0

如果使用comment.persisted?,它可能會更具可讀性 – BroiSatse

相關問題