开发者

distance_of_time_in_words with ActiveRecord TimeWithZone

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜