【发布时间】:2016-02-05 08:43:11
【问题描述】:
我将 paper_trail gem 用于 Rails 项目。 (红宝石 2.3,轨道 4.2.5)
paper_trail 没有在我的 rails 应用程序中跟踪 :destroy 事件。
经过调查,带有destroy 事件的版本模型似乎没有被保存,因为它与它应该跟踪的模型有关系,并且现在不存在(我们正在记录一个销毁事件,因此有意使该模型此时不存在)。
这就是我试图背后的方法:
PaperTrail 有一个名为Version 的模型。当我设置断点at the point 时,应该保存带有destroy 事件的Version 实例,我可以看到模型没有验证。当我尝试保存版本模型时收到此消息:
ActiveRecord::RecordInvalid: Validation failed: Item can't be blank
当我查看哪些验证器属于版本模型时,我可以看到 :item 是一个验证属性:
[<ActiveRecord::Validations::PresenceValidator:0x007fe90cb3be40 @attributes=[:event], @options={}>,
<ActiveRecord::Validations::PresenceValidator:0x007fe9044c82a0 @attributes=[:event], @options={}>,
<ActiveRecord::Validations::PresenceValidator:0x007fe9044cbce8 @attributes=[:item_type], @options={}>,
<ActiveRecord::Validations::PresenceValidator:0x007fe90e022f20 @attributes=[:item], @options={}>]
这里有什么我遗漏的吗?我的 activerecord 模型非常简单:
class ClientNote < ActiveRecord::Base
has_paper_trail
end
【问题讨论】:
标签: ruby-on-rails ruby activerecord paper-trail-gem