diff --git a/lib/cramp/model/attribute_methods.rb b/lib/cramp/model/attribute_methods.rb index 4352832..bb3e35c 100644 --- a/lib/cramp/model/attribute_methods.rb +++ b/lib/cramp/model/attribute_methods.rb @@ -42,7 +42,10 @@ def write_attribute(name, value) if ma = self.class.model_attributes[name.to_sym] value = ma.check_value!(value) end - @attributes[name] = value + if(@attributes[name] != value) + send "#{name}_will_change!".to_sym + @attributes[name] = value + end end def read_attribute(name) diff --git a/lib/cramp/model/base.rb b/lib/cramp/model/base.rb index 8cf0dcc..9997b62 100644 --- a/lib/cramp/model/base.rb +++ b/lib/cramp/model/base.rb @@ -5,6 +5,7 @@ class Base extend Finders include AttributeMethods include ActiveModel::Validations + include ActiveModel::Dirty include Callbacks class << self @@ -82,6 +83,11 @@ def update_record(callback = nil, &block) end def after_save(status) + if status.success? + previously_changed_attributes = changes + changed_attributes.clear + end + after_save_callbacks status end