已审核 Gem 对销毁添加评论

Audited Gem Add Comment on Destroy

我已经实施了 Audited,一切正常。我唯一想不通的是如何在删除记录时添加“audit_comment”。我可以在更新或创建时成功添加它,但我没有看到任何允许我在删除时添加评论的内容。

我的示例是,我可以直接删除记录,也可以通过相关关联的回调将其删除。所以我想根据情况在审核中添加评论...“直接由用户删除”或“通过父删除删除”

我是否遗漏了审核文件中的内容?

你需要在销毁之前添加评论,像这样:

model.audit_comment = 'some random comment'
model.destroy

按照这里的描述https://github.com/collectiveidea/audited/blob/master/lib/audited/auditor.rb#L11

To store an audit comment set model.audit_comment to your comment before a create, update or destroy operation.

这里还有更多代码https://github.com/collectiveidea/audited/blob/master/lib/audited/auditor.rb#L303

def audit_destroy
  unless new_record?
    write_audit(action: "destroy", audited_changes: audited_attributes, comment: audit_comment)
  end
end