【发布时间】:2015-11-21 05:00:12
【问题描述】:
我想将 EST 中的时间保存在我的数据库中。我希望rails将它作为存储在数据库中的时间来读取。我将 config/application.rb 文件中的设置更改为此
config.time_zone = 'Eastern Time (US & Canada)'
config.active_record.default_timezone = 'Eastern Time (US & Canada)'
现在,当我将条目保存到数据库中时,它们与 EST 一起正确存储在 created_at 字段中。第二个字段创建于,直接来自 postgres:
4453 | 2015-08-26 20:04:07.023224 | mlb | team_scores_first | fg | 0 | 2015-08-24 | {"away":"NYM","home":"PHI"} | 1104 | 1103 | 541220 | {"away":-225.0,"home":185.0}
但是当我通过 rails 获取记录时,它给了我这个
<Line id: 4453, created_at: nil, league: "mlb", bet_type: "team_scores_first", period: "fg", book: 0, date: "2015-08-24", names: {"away"=>"NYM", "home"=>"PHI"}, away_team_id: 1104, home_team_id: 1103, game_id: 541220, line: {"away"=>-225.0, "home"=>185.0}>
为什么 Rails 对 created_at 字段返回 nil?需要进行哪些更改才能将 created_at 字段读取为存储在 DB 中的日期时间?
【问题讨论】:
标签: ruby-on-rails postgresql timezone timestamp