【问题标题】:Rendering amount of months something was done in html.erb在 html.erb 中完成了几个月的渲染
【发布时间】:2021-03-25 20:25:13
【问题描述】:

我想知道是否有可能从响应中获得几个月的轨道。 如果我的数据包含published.at: '2020-12-31 08:00:00 UTC'。 如何在我的 html Published: 3 months ago 中呈现而不是显示整个日期? 现在我显示为<%= item.published_at %>

【问题讨论】:

  • 这个有没有像样的答案:stackoverflow.com/questions/9428605/…
  • @BenStephens 只需要在 html 中完成此操作
  • 我不确定我是否理解,它在 ERB 中不是吗?如果是,您应该可以将 ruby​​ 代码放在那里。

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

您可以使用time_ago_in_words

Published <%= time_ago_in_words(item.published_at) %> ago

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    相关资源
    最近更新 更多