2011-01-07 92 views
1

我認爲這可能是由於移動到了activesupport 2.3.5,但現在我相信其他事情一定發生了。Rails time_ago_in_words產生錯誤的輸出

模型有一個有效RFC822風格日期:

>> s.lastVisitDate 
=> "Thu, 06 Jan 2011 22:24:10 -0800" 

但筆者認爲:

<%=h time_ago_in_words(@site.lastVisitDate) -%> 

renders: *about {{count}} hours ago* 
instead of: *about 2 hours ago* which was working just fine earlier. 

想知道是否有人看到這種行爲。我已經查看了模型和視圖的版本歷史記錄,最近沒有發生任何變化,所以我相信我必須在事物的配置方面搞砸了一些東西。

回答

0

我發現我在一個語言環境文件中缺少適當的值。

所以在我的情況下,我增加了以下內容/config/locales/en.yml

我不知道爲什麼,這是以前的工作或有什麼具體的寶石或配置變化來觸發這個問題,但這裏具有適當的定義讓行動裝滿意。

# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words() 
    datetime: 
    distance_in_words: 
     half_a_minute: "half a minute" 
     less_than_x_seconds: 
     one: "less than 1 second" 
     other: "less than %{count} seconds" 
     x_seconds: 
     one: "1 second" 
     other: "%{count} seconds" 
     less_than_x_minutes: 
     one: "less than a minute" 
     other: "less than %{count} minutes" 
     x_minutes: 
     one: "1 minute" 
     other: "%{count} minutes" 
     about_x_hours: 
     one: "about 1 hour" 
     other: "about %{count} hours" 
     x_days: 
     one: "1 day" 
     other: "%{count} days" 
     about_x_months: 
     one: "about 1 month" 
     other: "about %{count} months" 
     x_months: 
     one: "1 month" 
     other: "%{count} months" 
     about_x_years: 
     one: "about 1 year" 
     other: "about %{count} years" 
     over_x_years: 
     one: "over 1 year" 
     other: "over %{count} years" 
     almost_x_years: 
     one: "almost 1 year" 
     other: "almost %{count} years" 
    prompts: 
     year: "Year" 
     month: "Month" 
     day: "Day" 
     hour: "Hour" 
     minute: "Minute" 
     second: "Seconds" 
+0

也許你以前在`Gemfile`中有`rails-i18n` gem。 – 2012-10-26 17:44:16