开发者

distance_of_time_in_words with ActiveRecord TimeWithZone

开发者 https://www.devze.com 2023-03-11 11:36 出处:网络
I\'m trying to use distance_of_time_in_words (Rails 3) on a created_at column of an A开发者_如何学GoctiveRecord object.

I'm trying to use distance_of_time_in_words (Rails 3) on a created_at column of an A开发者_如何学GoctiveRecord object.

But I get

ActiveSupport::TimeWithZone can't be coerced into Fixnum

when I call

distance_of_time_in_words(@user.created_at)

Any ideas?


You need to supply the to_time as well. Assuming you want to know "how long ago from right now":

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

Alternatively, you could just do this:

<%= distance_of_time_in_words_to_now(@user.created_at) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消