Distance_of_time_in_words with ActiveRecord TimeWithZone

I am trying to use distance_of_time_in_words(Rails 3) in created_atan ActiveRecord object column .

But I get

ActiveSupport::TimeWithZone can't be coerced into Fixnum

when i call

distance_of_time_in_words(@user.created_at)

Any ideas?

+3
source share
1 answer

You also need to supply to_time. Assuming you want to know "how long since now":

<%= distance_of_time_in_words(@user.created_at, Time.now) %>

Alternatively, you can simply do this:

<%= distance_of_time_in_words_to_now(@user.created_at) %>
+5
source

All Articles