I have set the default time zone in config/application.rb by adding the following:
config.time_zone = 'Pacific Time (US & Canada)'
config.active_record.default_timezone = :local
Even though Time.now shows the right time zone and the query generated is showing the right time zone when retrieving the record with ActiveRecord, I am getting the wrong time zone. How to fix that?
irb(main):010:0> Time.now
=> 2015-01-15 00:17:18 -0800
irb(main):011:0> Article.first.update_attributes(:updated_at => Time.now)
Article Load (0.2ms) SELECT "articles".* FROM "articles" ORDER BY "articles"."id" ASC LIMIT 1
(0.1ms) begin transaction
SQL (0.3ms) UPDATE "articles" SET "updated_at" = ? WHERE "articles"."id" = ? [["updated_at", "2015-01-15 00:17:23.369993"], ["id", 1]]
(4.7ms) commit transaction
=> true
irb(main):012:0> Article.first
Article Load (0.2ms) SELECT "articles".* FROM "articles" ORDER BY "articles"."id" ASC LIMIT 1
=> #<Article id: 1, title: "First article updated", body: "This is my first article", published_at: "2015-01-14 06:53:00", created_at: "2015-01-14 06:53:38", updated_at: "2015-01-15 08:17:23", excerpt: nil, location: nil>
Aucun commentaire:
Enregistrer un commentaire