I wanted to display datetime in words, like "1 hour ago" and i tried the following method but it is returning returning html in the string format as shown below.
helper.time_ago_in_words(Time.now)
=> "<span class=\"translation_missing\" title=\"translation missing: en.less_than_x_minutes\">Less Than X Minutes</span>"
rails console output:
>> helper.time_ago_in_words(Time.now)
=> "<span class=\"translation_missing\" title=\"translation missing: en.less_than_x_minutes\">Less Than X Minutes</span>"
>> I18n.locale = :de
=> :de
>> helper.time_ago_in_words(Time.now)
=> "<span class=\"translation_missing\" title=\"translation missing: de.less_than_x_minutes\">Less Than X Minutes</span>"
>> I18n.locale = :en
=> :en
>> helper.time_ago_in_words(Time.now)
=> "<span class=\"translation_missing\" title=\"translation missing: en.less_than_x_minutes\">Less Than X Minutes</span>"
Do you use any locales in config? English is for sure the default one and it should work correctly.
2.0.0p0 :001 > helper.time_ago_in_words(Time.now)
=> "less than a minute"
2.0.0p0 :002 > I18n.locale = :de
=> :de
2.0.0p0 :003 > helper.time_ago_in_words(Time.now)
=> "translation missing: de.datetime.distance_in_words.less_than_x_minutes"
2.0.0p0 :004 > I18n.locale = :en
=> :en
2.0.0p0 :005 > helper.time_ago_in_words(Time.now)
=> "less than a minute"
Could you try to invoke this method on helper object, like I did in console (rails c)? What is the output?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With