Sha256: f3cfdd4d3f697e8cb1773b2167c53430d497be7606ef259dbc8df4990f68d2f2

Contents?: true

Size: 792 Bytes

Versions: 9

Compression:

Stored size: 792 Bytes

Contents

# Example from 'Overwriting default accessors' in ActiveRecord::Base.
class Song < ActiveRecord::Base
  has_paper_trail
  attr_accessor :name

  # Uses an integer of seconds to hold the length of the song
  def length=(minutes)
    write_attribute(:length, minutes.to_i * 60)
  end
  def length
    read_attribute(:length) / 60
  end

  # override attributes hashes like some libraries do
  def attributes_with_name
    if name
      attributes_without_name.merge(:name => name)
    else
      attributes_without_name
    end
  end
  alias_method_chain :attributes, :name

  def changed_attributes_with_name
    if name
      changed_attributes_without_name.merge(:name => name)
    else
      changed_attributes_without_name
    end
  end
  alias_method_chain :changed_attributes, :name
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paper_trail-4.2.0 test/dummy/app/models/song.rb
paper_trail-4.1.0 test/dummy/app/models/song.rb
paper_trail-4.0.2 test/dummy/app/models/song.rb
paper_trail-4.0.1 test/dummy/app/models/song.rb
paper_trail-3.0.9 test/dummy/app/models/song.rb
paper_trail-4.0.0 test/dummy/app/models/song.rb
paper_trail-4.0.0.rc2 test/dummy/app/models/song.rb
paper_trail-4.0.0.rc1 test/dummy/app/models/song.rb
paper_trail-3.0.8 test/dummy/app/models/song.rb