【问题标题】:Rails time_ago_in_words producing bad outputRails time_ago_in_words 产生错误的输出
【发布时间】:2011-01-07 08:29:44
【问题描述】:

我认为这可能是由于迁移到 activesupport 2.3.5,但现在我相信一定发生了其他事情。

模型具有有效的 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.

想知道是否有其他人看到过这种行为。我已经查看了模型和视图的版本历史,最近没有任何变化,所以我相信我一定是在配置方面搞砸了。

【问题讨论】:

    标签: ruby-on-rails activesupport


    【解决方案1】:

    我发现我在语言环境文件中缺少适当的值。

    所以在我的情况下,我将以下内容添加到 /config/locales/en.yml

    我不确定为什么这以前有效,或者什么特定的 gem 或配置更改触发了这个问题,但是在这里有正确的定义会让 actionpack 很高兴。

    # 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"
    

    【讨论】:

    • 也许您之前在您的Gemfile 中有rails-i18n gem。
    猜你喜欢
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    相关资源
    最近更新 更多