2012-09-10 76 views
0

這裏是我的en.yml區域Ruby on Rails的time_ago_in_words不顯示秒前

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" 

每當我張貼的東西我使用

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

到以前顯示的時間,因爲後被創建,但不是顯示1秒,2秒等...它顯示1分鐘,並繼續無線第分鐘

回答

3

您必須通過truetime_ago_in_wordsinclude_seconds參數:

time_ago_in_words(post.created_at, true) 

documentation for distance_of_time_in_words,這是爲更詳細地使用time_ago_in_words

+0

謝謝,現在還有一個問題......它不會顯示1乘1秒......只有5乘以5或甚至更多像10乘10秒...... – fxuser

+0

這就是函數的工作原理,它顯示了大致的時間不是一個確切的(見['distance_of_time_in_words'代碼](https://github.com/rails/rails/blob/bd8a9701c27b4261e9d8dd84aebbde6ba784ed83/actionpack/lib/action_view/helpers/date_helper.rb#L80))。如果你想要確切的時間,你需要編寫自己的幫手。 – georgebrock