2017-01-12 63 views
3

我遇到Rails 4和5之間的不同行爲;具體而言,代碼中的模型的值爲created_atupdated_at。在Rails 4中,它顯示它們是ActiveSupport::TimeWithZone,但Rails 5只是將它們作爲Date。這些值(顯然)與puts的打印方式不同。Rails 5 - created_at和updated_at類

我還沒有改變這些值的數據庫類型。我正在使用Oracle和activerecord-oracle_enhanced-adapter gem(v1.7.0),並且這些列在遷移過程中「正常」創建,沒有特殊配置,因此爲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 

他們真的改變這種情況,還是我做錯了什麼?我錯過了什麼?

+0

您使用的數據庫是什麼,它對created_at列的數據類型有什麼看法? – Maltiriel

+0

@Maltiriel:用db數據更新了問題。 – istrasci

回答

相關問題