Sha256: ea267f6906365959b1e46c46270c080216cefabeca71ba6712c869538edef996

Contents?: true

Size: 662 Bytes

Versions: 13

Compression:

Stored size: 662 Bytes

Contents

class Person < ActiveRecord::Base
  has_many :authorships, :dependent => :destroy
  has_many :books, :through => :authorships
  has_paper_trail

  # Convert strings to TimeZone objects when assigned
  def time_zone=(value)
    if value.is_a? ActiveSupport::TimeZone
      super
    else
      zone = ::Time.find_zone(value)  # nil if can't find time zone
      super zone
    end
  end

  # Store TimeZone objects as strings when serialized to database
  class TimeZoneSerializer
    def dump(zone)
      zone.try(:name)
    end
   
    def load(value)
      ::Time.find_zone!(value) rescue nil
    end
  end
 
  serialize :time_zone, TimeZoneSerializer.new
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
paper_trail-3.0.7 test/dummy/app/models/person.rb
paper_trail-3.0.6 test/dummy/app/models/person.rb
paper_trail-3.0.5 test/dummy/app/models/person.rb
paper_trail-3.0.2 test/dummy/app/models/person.rb
paper_trail-3.0.1 test/dummy/app/models/person.rb
paper_trail-3.0.0 test/dummy/app/models/person.rb
paper_trail-3.0.0.rc2 test/dummy/app/models/person.rb
paper_trail-3.0.0.rc1 test/dummy/app/models/person.rb
paper_trail_without_deprecated-3.0.0.beta1 test/dummy/app/models/person.rb
paper_trail-3.0.0.beta1 test/dummy/app/models/person.rb
paper_trail-2.7.2 test/dummy/app/models/person.rb
paper_trail-2.7.1 test/dummy/app/models/person.rb
paper_trail-2.7.0 test/dummy/app/models/person.rb