Ruby Flare

Your awesome Tagline

4 notes

Skip automatic time zone conversion

Use the following in your ActiveRecord model when you want to avoid Rails automatically converting your times according to your timezone:

def self.skip_time_zone_conversion_for_attributes
  [:approved_at, :published_at]
end

Or, for a single attribute:

skip_time_zone_conversion_for_attributes << :exposed_at

You can also turn off automatic time zone conversion for an entire model:

def self.time_zone_aware_attributes
  false
end

Now whatever you set for your time attributes, that is what will be stored in the database.

(Source: info.michael-simons.eu)

Filed under timezones rails activerecord

  1. rubyflare posted this