CSS样式Time_Ago_in_Words Rails
-
14-11-2019 - |
题
我想知道如何定制Rails Helper:time_ago_in_words的最佳解决方案,这样我就可以做的事情:
<span class="one">4</span>
<span class="two">hours</span>
<span class="three">ago</span>
.
或默认情况下的布局看起来像什么?
感谢
解决方案
I would just create a helper that splits the result of time_ago_in_words on spaces and returns the array of words. Then you can format them however you want.
其他提示
Instead of the method time_ago_in_words
, you can use distance_of_time_in_words, which accepts locale in the option array: create a new locale where you can define "hours" with "hours", etc... and give it to distance_of_time_in_words
. It should work, but I'm not sure how will be handled the HTML tags.
不隶属于 StackOverflow