Если вы хотите сделать это для конкретной модели или для определенных полей в конкретной модели, метод, описанный в этом посте , сработал для меня.
# Turn it off for just some columns
class Picture < ActiveRecord::Base
def self.skip_time_zone_conversion_for_attributes
[:created_at, :published_at]
end
end
# Turn it off for the whole model
class Picture < ActiveRecord::Base
def self.time_zone_aware_attributes
false
end
end
И если это поможет, вот мой тестовый пример:
before :all do
@current_tz = Time.zone
# Test usually runs in UTC; test this as if in production, per config/application.rb
Time.zone = 'Pacific Time (US & Canada)'
end
after :all do
Time.zone = @current_tz
end
it 'should report UTC time as UTC time' do
new_obj = MyModel.create(start_time: DateTime.new(2013, 3, 31, 0, 0, 0, 0))
new_obj.reload
new_obj.start_time.to_s.should == 'Sun, 31 Mar 2013 00:00:00 +0000'
end