DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Return A Hash Of ActiveRecord Attributes Prior To Changes

07.15.2009
| 6384 views |
  • submit to reddit
        This method returns a hash of ActiveRecord attributes in the state prior to any changes.
class ActiveRecord::Base
  def was
    attributes.merge(changes){|key, old_val, new_val| new_val[0]}
  end
end