Created
June 30, 2009 02:06
-
-
Save nikz/137941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Wrap write_attribute to remember original attribute value. | |
| def write_attribute_with_dirty(attr, value) | |
| attr = attr.to_s | |
| # The attribute already has an unsaved change. | |
| if changed_attributes.include?(attr) | |
| old = changed_attributes[attr] | |
| changed_attributes.delete(attr) unless field_changed?(attr, old, value) | |
| else | |
| old = clone_attribute_value(:read_attribute, attr) | |
| changed_attributes[attr] = old if field_changed?(attr, old, value) | |
| end | |
| # Carry on. | |
| write_attribute_without_dirty(attr, value) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment