如何仅在创建事件类型时在 PaperTrail 中捕获自定义元数据并在更新和销毁时正常工作

问题描述 投票:0回答:1

has_paper_trail on: [:create], meta: { object: "custom data" }

这只适用于创建事件

has_paper_trail on: [:create], meta: { object: "custom data" }
has_paper_trail on: [:update, destroy]

除了创建之外,还尝试过以这种方式处理其他事件 但第二个调用会覆盖第一个调用

我只需要自定义数据,以防创建和其他事件应该正常工作

ruby-on-rails paper-trail-gem
1个回答
0
投票

尝试使用仅在对象是新记录时返回元数据的 lambda...

has_paper_trail on: [:create, :update, :destroy], 
                meta: Proc.new { |t| t.new_record? ? { object: "custom data" } : nil }
© www.soinside.com 2019 - 2024. All rights reserved.