【问题标题】:Rails 5 - created_at and updated_at classesRails 5 - created_at 和 updated_at 类
【发布时间】:2017-05-26 23:25:31
【问题描述】:

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

我没有更改这些值的数据库类型。我正在使用带有 activerecord-oracle_enhanced-adapter gem (v1.7.0) 的 Oracle,并且这些列是在使用 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

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

【问题讨论】:

  • 您使用的是什么数据库,它对 created_at 列的数据类型有何说明?
  • @Maltiriel:使用数据库信息更新问题。

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


【解决方案1】:

我在 activerecord-oracle_enhanced-adapter 文档中错过了这一点,但我需要申请明确的 Rails 4.2 to 5 upgrade instructions

【讨论】:

  • 在找到您的问题之前,我也没有阅读文档。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-15
  • 1970-01-01
  • 2010-10-18
  • 2011-07-17
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
相关资源
最近更新 更多