Skip to content
This repository
Browse code

override #save to add reset_changes

  • Loading branch information...
commit 654b778dcb50920e2632a797bf838a9fec84159d 1 parent d30d1c1
James Golick authored January 03, 2010
2  lib/friendly/document.rb
@@ -38,10 +38,10 @@ def table_name
38 38
     end
39 39
 
40 40
     include Associations
41  
-    include Attributes
42 41
     include Convenience
43 42
     include Scoping
44 43
     include Storage
  44
+    include Attributes
45 45
 
46 46
     def table_name
47 47
       self.class.table_name
11  lib/friendly/document/attributes.rb
@@ -78,7 +78,7 @@ def changed
78 78
       # Reset all the changes to this object.
79 79
       #
80 80
       def reset_changes
81  
-        changed.each { |c| not_changed(c) }
  81
+        changed.each { |c| not_changed(c) }.clear
82 82
       end
83 83
 
84 84
       # Reset the changed-ness of one attribute.
@@ -88,6 +88,15 @@ def not_changed(attribute)
88 88
         changed.delete(attribute)
89 89
       end
90 90
 
  91
+      # Override #save to reset changes afterwards
  92
+      #
  93
+      # @override
  94
+      #
  95
+      def save
  96
+        super
  97
+        reset_changes
  98
+      end
  99
+
91 100
       protected
92 101
         def assert_no_duplicate_keys(hash)
93 102
           if hash.keys.map { |k| k.to_s }.uniq.length < hash.keys.length

0 notes on commit 654b778

Please sign in to comment.
Something went wrong with that request. Please try again.