我想顯示日期時間的單詞,如「1小時前」,我試着下面的方法,但它返回字符串格式返回HTML,如下所示。Rails 3.2時間前在文字方法返回html內容
方法
helper.time_ago_in_words(Time.now)
結果
=> "<span class=\"translation_missing\" title=\"translation missing: en.less_than_x_minutes\">Less Than X Minutes</span>"
軌控制檯輸出:
>> 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>"
你右邊的文檔像它應該返回爲特林... http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_ago_in_words。我不知道一個解決方案,但感謝您提出這個問題,以便我和其他人稍後可以留心。 – rovermicrover