我是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
最佳答案
在格式化之前,您应该将时间转换为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/