最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby - How to Pass whodunnit to PaperTrail When Using destroy_async in Rails 6.1+? - Stack Overflow

programmeradmin0浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论