Permalink
Browse files

Extract all attribute changed work to its own method

This will make easier to hook on this feature to customize the behavior
  • Loading branch information...
rafaelfranca committed Jan 20, 2014
1 parent b8302bc commit a4cc88d0851343ac16e2294c06c5a4101189c410
Showing with 7 additions and 3 deletions.
  1. +7 −3 activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -43,6 +43,13 @@ def reload(*)
def write_attribute(attr, value)
attr = attr.to_s
+ save_changed_attribute(attr, value)
+
+ # Carry on.
+ super(attr, value)
+ end
+
+ def save_changed_attribute(attr, value)
# The attribute already has an unsaved change.
if attribute_changed?(attr)
old = changed_attributes[attr]
@@ -51,9 +58,6 @@ def write_attribute(attr, value)
old = clone_attribute_value(:read_attribute, attr)
changed_attributes[attr] = old if _field_changed?(attr, old, value)
end
-
- # Carry on.
- super(attr, value)
end
def update_record(*)

0 comments on commit a4cc88d

Please sign in to comment.