我是 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):
此代码在我的 View /共享/事件文件中使用
<%= Time.at(event_item.created_at).strftime("%d-%b-%Y") %>
这段代码在我的本地生产机器上工作得很好,但在 heroku 机器上却不行,我完全混淆了,我认为 heroku 不支持 strftime,还有其他方法吗?等待您的帮助,在此先感谢。
注意:数据库使用Postgresql ruby 1.9.3 rails 3.2.8
最佳答案
在格式化之前,您应该将时间转换为 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
关于ruby-on-rails - Heroku 上的 strftime 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25106254/