Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 776
AnApprentice Avatar asked Sep 27 '10 05:09

AnApprentice


3 Answers

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.

like image 195
Dave Pirotte Avatar answered Sep 21 '22 08:09

Dave Pirotte


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>
like image 26
Chris Hawkins Avatar answered Sep 20 '22 08:09

Chris Hawkins


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])
like image 25
Ryan Bigg Avatar answered Sep 20 '22 08:09

Ryan Bigg