Rails 3 - time_ago_in_words says “ABOUT 2 hours ago”

后端 未结 3 1842
忘掉有多难
忘掉有多难 2020-12-23 20:47

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 a

相关标签:
3条回答
  • 2020-12-23 21:25

    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>
    
    0 讨论(0)
  • 2020-12-23 21:37

    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.

    0 讨论(0)
  • 2020-12-23 21:44

    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 讨论(0)
提交回复
热议问题