Dylan Richards
Dylan Richards

Reputation: 708

undefined method `>' for nil:NilClass

The error occurs on this line:

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

Why is it happening, and how do I solve it?

I'm sorry for the lack of code provided. Just don't know what to give you guys.

Upvotes: 0

Views: 944

Answers (1)

Gjaldon
Gjaldon

Reputation: 5644

Did a quick browse on the code for time_ago_in_words and saw that it calls the method > in distance_of_time_in_words.

It is probably returning that error since the argument you provided, comment.created_at, is returning nil. This nil is then being compared to another value, which is why you are getting that error. Make sure that you don't provide a nil arg to time_ago_in_words by doing a nil conditional like:

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

Hope that helps!

Upvotes: 1

Related Questions