jeudi 22 juin 2017

Audits log with nested models

I'm using the gem audited to track database changes. I want to show the user a audition log, with all audits ordered by created_at. The problem is some audits are related to nested models, for example, a Person can have one address (and accepts_nested_attributes_for it). In this case there is no sense in showing the address changes in the Audits log, since it cannot be identified by the user, the address changes should register an Audit for the Person and then I should be able to find the children audits from it.

The solution I have found is to force a parent update from the child model so and Audit will be crated for the parent. Now, the problem is, there is no way to find the children Audits from this parent Audit. When the user click an Person Audit from the log list, I want to show him all changes that happened to the Person and also to it's address.

With the audited gem is possible to do

audited :associated_with => :person

but the audit will be associated to the parent model, and not to any Audit, so there is no way to tie together the parent and children audits. I can only access the entire list of audits for the address, and can't find the one that was associated to the audit I'm currently showing him.

Is there a way to accomplish this with the audited gem (hacks are welcome) or is there other gem that is able to do it (like papertrail) ?

Aucun commentaire:

Enregistrer un commentaire