Hi, 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:
“model.was”
or
“model.before_changes”
Also, I would like to have an option to revert all changes without reloading from DB. Something like:
“model.revert_changes”
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]}
result
end
def revert_changes
self.changes.each {|attr, values| self[attr] = values[0]}
end
Any thoughts on the subject?
- Regards,
– Adam Klein