I’m using the PaperTrail gem to track changes to my models, including deletions. My application is on Rails 7.2, and I want to leverage the destroy_async feature introduced in Rails 6.1.
Everything works as expected in terms of background deletion, but the problem is that PaperTrail does not capture the whodunnit when the destroy action is performed asynchronously.
What I’ve tried:
I wrapped the destroy call within PaperTrail.request(whodunnit: current_user), like this:
PaperTrail.request(whodunnit: current_user) do
object.destroy
end
However, this does not correctly associate the whodunnit with the deletion when destroy_async is used.
I also tried creating a custom background worker to handle the deletion while explicitly passing whodunnit. This worked but felt less clean compared to the built-in destroy_async feature.
Question:
Is there a clear way to pass whodunnit to PaperTrail when using destroy_async?
Any guidance would be greatly appreciated!