开发者

Rails 3 - time_ago_in_words says "ABOUT 2 hours ago"

Code:

开发者_运维知识库<%="#{time_ago_in_words(comment.created_at)} ago "%>

What i'd like is for it not to have "ABOUT" in front of the 2 hours ago, which shows up for hours but not for minutes...

Is there another function or a way to remove it without finding and replacing?


You can change this via your I18n locale file. In config/locales/en.yml...

"en":
  datetime:
    distance_in_words:
      about_x_hours:
        # The defaults are "about 1 hour" and "about %{count} hours"
        one: "1 hour"
        other: "%{count} hours"

See the default locale file in actionpack for a complete reference.


I had the same issue, I ended up doing this, mostly because I'm still up in the air about whether or not to remove the about globally -

<p class="entry_created_at"><%= time_ago_in_words(plate.created_at).gsub('about','') + ' ago' %></p>


You can use my dotiw gem/plugin for that. It adds a couple of additional options and has greater precision than the one Rails offers.

distance_of_time_in_words(time1, time2, :only => [:days, :hours, :minutes])
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜