gpt4 book ai didi

ruby-on-rails - 使用 time_ago_in_words 获得 {{count}}

转载 作者:行者123 更新时间:2023-12-04 06:27:40 27 4
gpt4 key购买 nike

我目前在我的应用程序中有此代码:

  def comment_poster(comment)
if comment.user
"posted by #{comment.user.username} #{time_ago_in_words(comment.created_at)} ago"
else
"posted by anonymous"
end
end

但是,这仅适用于我在几秒钟前和几年前发布的内容:
posted by teejay about 1 year ago
posted by teejay about 1 month ago

当我将 created_at 值编辑到几天前时,它给了我这个:
posted by thorpe {{count}} days ago

我应该怎么做才能让它工作并失去那个 {{count}}
编辑:如果这意味着什么,我正在使用 Rails 2.3.5

编辑:#2

我通过粘贴 this code 解决了这个问题在 config/locales/en.yml
  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"

谁能解释一下问题是什么?

最佳答案

问题出在 i18n gem 版本上。如果你降级到 0.4.1,这个问题就会消失。

问题是从 0.4.1 版本开始,访问变量的方式不再是 {{variable}}。

关于ruby-on-rails - 使用 time_ago_in_words 获得 {{count}},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4827767/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com