Rails 5 - created_at和updated_at类

时间:2017-01-12 00:37:49

标签: oracle types model ruby-on-rails-5

我在Rails 4和5之间遇到了不同的行为;具体而言,代码中模型的created_atupdated_at值类。在Rails 4中,它表明它们是ActiveSupport::TimeWithZone,但Rails 5只是将它们作为Date。这些值(显然)也会以puts打印出来。

我没有更改这些值的数据库类型。我使用Oracle和 activerecord-oracle_enhanced-adapter gem(v1.7.0),并且创建了列#34;通常"在t.timestamps的迁移中没有特殊配置。

» 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

他们真的改变了这个,还是我做错了什么?我错过了什么?

1 个答案:

答案 0 :(得分:4)

我在activerecord-oracle_enhanced-adapter文档中忽略了这一点,但我需要明确Rails 4.2 to 5 upgrade instructions