【问题标题】:strftime error on HerokuHeroku上的strftime错误
【发布时间】:2014-08-03 15:36:14
【问题描述】:

我是 RubyOnRails 新手,在 Heroku 机器上遇到 strftime 错误,下面的代码是用于验证的 heroku 日志。

2014-08-03T15:15:06.051867+00:00 app[web.1]: ActionView::Template::Error (can't convert 
ActiveSupport::TimeWithZone into an exact number):

此代码在我的视图/共享/事件文件中使用

<%= Time.at(event_item.created_at).strftime("%d-%b-%Y") %>

这段代码在我的本地生产机器上工作得很好,但不是在heroku机器上,我完全糊涂了,我认为heroku不支持strftime,还有其他方法吗?期待您的帮助,在此先感谢。

注意:将 Postgresql 用于数据库 红宝石 1.9.3 导轨 3.2.8

【问题讨论】:

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


    【解决方案1】:

    您应该在格式化之前将您的时间转换为DateTime

    当您最终显示日期时,我想这也应该适合您:

    <%= event_item.created_at.to_datetime.strftime("%d-%b-%Y") %>
    

    Time.at() 在这里似乎没用:

    Time.at(event_item.created_at).class     # => ActiveSupport::TimeWithZone
    event_item.created_at.class              # => ActiveSupport::TimeWithZone
    event_item.created_at.to_datetime.class  # => DateTime
    

    更多关于to_datetime

    【讨论】:

    • 嗨 Raj,太好了,非常感谢,谢谢 :)
    猜你喜欢
    • 2013-07-10
    • 2018-11-28
    • 1970-01-01
    • 2021-01-04
    • 2018-07-30
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多