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分钟,并继续无线第分钟
谢谢,现在还有一个问题......它不会显示1乘1秒......只有5乘以5或甚至更多像10乘10秒...... – fxuser
这就是函数的工作原理,它显示了大致的时间不是一个确切的(见['distance_of_time_in_words'代码](https://github.com/rails/rails/blob/bd8a9701c27b4261e9d8dd84aebbde6ba784ed83/actionpack/lib/action_view/helpers/date_helper.rb#L80))。如果你想要确切的时间,你需要编写自己的帮手。 – georgebrock