ActiveRecord
provides some methods that you can make use of
changed?
-> tells you id the object is changedchanged
-> gives an array of attributes that changedchanged_attributes
-> gives you a hash with keys as the changed attributes and values as old valuebefore_save :log_changed def log_changed if self.changed? self.changed.each do |attr| Update.create(:candidate_id => self.id, :field => attr, :new_value => self.attributes[attr], :old_value => self.changed_attributes[attr]) end end end