我在Rails 4和5之间经历了不同的行为;具体来说,代码中模型的created_at和updated_at值的类。在Rails 4中,它表明它们是ActiveSupport::TimeWithZone,但是Rails 5只是将它们作为Date。这些值也(显然)在puts中以不同的方式输出。
我没有更改这些值的数据库类型。我使用的是Oracle (v1.7.0),这些列是在没有特殊配置的activerecord-oracle_enhanced-adapter迁移过程中“正常”创建的。
» bundle exec rails c
Running via Spring preloader in process 69059
Loading development environment (Rails 4.2.7.1)
[1] (pry) main: 0> Rails.version
=> "4.2.7.1"
[2] (pry) main: 0> Document.first.created_at.class
[ SQL Omitted ]
=> ActiveSupport::TimeWithZone ←←←←←←←←←←←← HERE
[3] (pry) main: 0> puts Document.first.updated_at
[ SQL Omitted ]
2016-09-08 17:05:18 -0600 ←←←←←←←←←←←←←←←←← HERE
=> nil
[4] (pry) main: 0> !!!
» git flow feature checkout rails-5
Switched to branch 'feature/rails-5'
» bundle exec rails c
Running via Spring preloader in process 69533
Loading development environment (Rails 5.0.1)
[1] (pry) main: 0> Rails.version
=> "5.0.1"
[2] (pry) main: 0> Document.first.created_at.class
[ SQL Omitted ]
=> Date ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←← HERE
[3] (pry) main: 0> puts Document.first.updated_at
[ SQL Omitted ]
2016-09-08 ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←← HERE
=> nil他们真的改变了这一切,还是我做错了什么?我遗漏了什么?
发布于 2017-01-18 21:04:19
我在增强适配器文档中忽略了这一点,但是我需要应用明确的Rails 4.2至5升级说明。
https://stackoverflow.com/questions/41603279
复制相似问题