代码:
<%="#{time_ago_in_words(comment.created_at)} ago "%>
我想要的是它在2小时前没有“关于”,这显示了几个小时而不是几分钟......
是否有其他功能或方法在不查找和替换的情况下将其删除?
答案 0 :(得分:59)
您可以通过I18n语言环境文件进行更改。在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"
请参阅default locale file in actionpack以获取完整参考。
答案 1 :(得分:12)
我遇到了同样的问题,我最终做到了这一点,主要是因为我还在讨论是否要删除全球范围内的问题 -
<p class="entry_created_at"><%= time_ago_in_words(plate.created_at).gsub('about','') + ' ago' %></p>
答案 2 :(得分:7)
您可以使用我的dotiw gem /插件。它增加了一些额外的选项,并且比Rails提供的精度更高。
distance_of_time_in_words(time1, time2, :only => [:days, :hours, :minutes])