Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 Time ago in words Method returns html content

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.

method

helper.time_ago_in_words(Time.now)

result

=> "<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>"
like image 223
Rahul Chandra Avatar asked Jan 18 '26 21:01

Rahul Chandra


1 Answers

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?

like image 160
konole Avatar answered Jan 20 '26 14:01

konole