auditable
auditable copied to clipboard
How to load an object how it looked at a previous version
Is there an easy way to load an object how it looked at a current state in its lifecycle?
E.g. I'm at version 110 and want to look how the object looked at version 80 including nested objects?
So the docs need updating, but if you have the version option set to true
audit :title, :version => true
You can simply use AREL to find by version:
model.audits.where(:version => 80).first
Yes, but that gives me an Auditable::Audit object.
I'm more looking for a way to update the attributes of an object directly with the modifications of an audit object but as far as I've seen there isn't something implemented in auditable yet?
E.g. to retrieve version 80 of a specific object someone would call something like audited_version(80)
on a specific object:
model.audited_version(80)
# => Model id: 1, attribute_1: "string", attribute_2: "string"
So you want to replay all the audits up to a version? It could work by merging all the audits together to make a hash of attributes and that could be applied to the model to return to that version's state.