Multiple associations with rails Audited

1.3k Views Asked by At

I am using the Audited gem for Rails, and am using the associated audits like so:

audited allow_mass_assignment: true, associated_with: :protocol

The problem is, I need this particular model's audits to be associated with more than one models. I was hoping that something like this will work:

audited allow_mass_assignment: true, associated_with: [:protocol, :patient]

But it doesn't. It provides a clear error stating:

[:protocol, :patient] is not a symbol nor a string

The only related page I could find claims it is simply not possible, but it is quite old and I hope there is some workaround.

Any help is appreciated as always.

2

There are 2 best solutions below

0
On

For anyone searching if you can use associated_with with multiple associations, currently that is not possible.

Although, someone submitted a PR, it did not work as expected.

0
On

Not tested it but try it on seperate lines, like:

audited allow_mass_assignment: true, associated_with: :protocol
audited allow_mass_assignment: true, associated_with: :patient