Changed attributes plugin

Plugin details

Allows you to keep track of changed attributes, test if an attribute has been modified, revert any or all attributes, and access the original attribute values at any time.

Note especially that this is the most memory-efficient way to go if you will be validate a lot of objects, needing to compare new with old values, or otherwise know whether an attribute was changed or not.

The only alternative to this plugin would be to do another database lookup to compare similar objects.

Websitehttp://blog.behindlogic.com/ Repositoryhttp://svn.behindlogic.com/public/rails/plugins/changed_attributes/ Author dcparker Tags Date LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.behindlogic.com/public/rails/plugins/changed_attributes/

Examples below

p = Person.find(1)
 => 

p.changed_attributes
 => {}

p.name = 'Joe Smith'
p.changed_attributes
 => {'name' => 'Joe Smith'}

p.revert_attribute(:name)
p.name
 => "Danl Boone"

p.age = 59
p.save_if_modified
 => true

p.save_if_modified
 => false

p.age = 220
p.attr_changed?(:age)
 => true

p.revert
p.age
 => 59

p.destroy
p.new_record?
 => false

p.id
 => 1

p.exists?
 => false

p.save
 => true

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: Guest, 8 months ago