应用程序显示错误的小时和分钟
首先:这不是错误区域的问题。在 irb 和数据库中一切都很好。当我想在视图中显示日期(created_at、updated_at 以及所有由我自己在每个模型中定义的日期)时,就会出现问题。我试图在 application.rb 中设置时区并从初始化程序中删除时间格式,但这并没有解决我的问题。
Annotate gem 生成的架构信息:
# created_at :datetime
# updated_at :datetime
# publish_at :datetime
来自 irb:
1.9.2-p290 :004 > Time.zone
=> (GMT+00:00) UTC
1.9.2-p290 :005 > Time.zone.now
=> Fri, 24 Feb 2012 12:14:04 UTC +00:00
1.9.2-p290 :006 > Time.now
=> 2012-02-24 13:14:07 +0100
示例:
1.9.2-p290 :007 > Article.last
Article Load (0.3ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` DESC LIMIT 1
=> #<... created_at: "2012-02-24 12:04:24", updated_at: "2012-02-24 12:04:24", publish_at: "2012-02-24 12:04:24"...>
应用显示:
Created_at 2012-02-24 12:02, 更新于 2012-02-24 12:02, Publish_at 2012-02-24 12:02,
1.9.2-p290 :008 > Article.first
Article Load (0.5ms) SELECT `articles`.* FROM `articles` LIMIT 1
=> #<...created_at: "2012-01-30 10:28:07", updated_at: "2012-02-08 17:20:41", publish_at: "2012-02-08 17:20:33"...>
应用程序显示:
Created_at 2012-01-30 10:01, 更新于 2012-02-08 17:02, Publish_at 2012-02-08 17:02
这适用于整个应用程序(包括active_admin)
抱歉我的英语;)有什么想法我的问题的原因是什么?
At first: thats not issue of wrong zone. In irb and database everything is fine. Problem occurs when I want to display dates (created_at, updated_at and all defined by myself in every model) in my views. I was trying to set time zone in application.rb and remove time formats from initializers and that didn't solved my issue.
schema information generated by Annotate gem:
# created_at :datetime
# updated_at :datetime
# publish_at :datetime
from irb:
1.9.2-p290 :004 > Time.zone
=> (GMT+00:00) UTC
1.9.2-p290 :005 > Time.zone.now
=> Fri, 24 Feb 2012 12:14:04 UTC +00:00
1.9.2-p290 :006 > Time.now
=> 2012-02-24 13:14:07 +0100
Examples:
1.9.2-p290 :007 > Article.last
Article Load (0.3ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` DESC LIMIT 1
=> #<... created_at: "2012-02-24 12:04:24", updated_at: "2012-02-24 12:04:24", publish_at: "2012-02-24 12:04:24"...>
App displays:
Created_at 2012-02-24 12:02,
Updated_at 2012-02-24 12:02,
Publish_at 2012-02-24 12:02,
1.9.2-p290 :008 > Article.first
Article Load (0.5ms) SELECT `articles`.* FROM `articles` LIMIT 1
=> #<...created_at: "2012-01-30 10:28:07", updated_at: "2012-02-08 17:20:41", publish_at: "2012-02-08 17:20:33"...>
App displays:
Created_at 2012-01-30 10:01,
Updated_at 2012-02-08 17:02,
Publish_at 2012-02-08 17:02
this applies whole app (including active_admin)
Sorry for my English ;) Any ideas what is the reason of my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白了:)这很愚蠢,但也许有人需要提醒:应用程序首先从语言环境 yml 文件获取格式(这是在活动管理中设置日期格式的唯一方法;初始化程序的格式并不重要):
和 ofc 分钟长格式应为 %M (而不是 %m)
I've got it :) That was silly, but maybe someone will need reminder: App gets format from locale yml file first (thats only way to set date format in active admin; formats from initializers doesn't matter):
and ofc minutes in long format should be %M (not %m)