2

Here is my en.yml locale

en:
  datetime:
    distance_in_words:
      less_than_x_seconds:
        one: "1 sec"
        other: "%{count} secs"
      x_seconds:
        one: "1 sec"
        other: "%{count} secs"
      less_than_x_minutes:
        one: "1 min"
        other: "%{count} mins"
      x_minutes:
        one: "1 min"
        other: "%{count} mins"
      about_x_hours:
        one: "1 hour"
        other: "%{count} hours"
      x_days:
        one: "1 day"
        other: "%{count} days"
      about_x_months:
        one: "1 month"
        other: "%{count} months"
      x_months:
        one: "1 month"
        other: "%{count} months"
      about_x_years:
        one: "1 year"
        other: "%{count} years"
      over_x_years:
        one: "1 year"
        other: "%{count} years"
      almost_x_years:
        one: "1 year"
        other: "%{count} years"

Whenever i post something i use

<%= link_to time_ago_in_words(post.created_at), post_path(post) %>

to display the time ago since the post was created but instead of showing 1 sec, 2 secs etc... it displays 1 min, and continues with minutes

stergosz
  • 5,754
  • 13
  • 62
  • 133

1 Answers1

4

You need to pass true to time_ago_in_words's include_seconds parameter:

time_ago_in_words(post.created_at, true)

See the documentation for distance_of_time_in_words, which is used by time_ago_in_words for more detail.

georgebrock
  • 28,393
  • 13
  • 77
  • 72
  • thanks, there is another problem now... it wont display 1 by 1 seconds... just 5 by five or even more like 10 by 10 seconds... – stergosz Sep 10 '12 at 07:42
  • That's how the function works, it shows an approximate time not an exact one (see [`distance_of_time_in_words` code](https://github.com/rails/rails/blob/bd8a9701c27b4261e9d8dd84aebbde6ba784ed83/actionpack/lib/action_view/helpers/date_helper.rb#L80)). If you want exact times you need to write your own helper. – georgebrock Sep 10 '12 at 07:46