Feature Request for ActiveModel::Dirty - a "model_was" and a "revert_changes" methods

I’ve encountered a need to see the model’s state before all the changes that were made to it.

I fantasized on something like this:




Also, I would like to have an option to revert all changes without reloading from DB. Something like:


I want to make a pull request with the following solution:

def was

result = self.dup.tap { |model| model.id = self.id }

self.changes.each {|attr, values| result[attr] = values[0]}



def revert_changes

self.changes.each {|attr, values| self[attr] = values[0]}


Any thoughts on the subject?

  • Regards,

– Adam Klein


Another option I thought about -
revert_changes will return the model before the changes but without changing the object

revert_changes! will revert the changes on the object itself and return it