Ruby on rails 如何在书面记录中使用带有meta的自定义版本表?

Ruby on rails 如何在书面记录中使用带有meta的自定义版本表?,ruby-on-rails,paper-trail-gem,Ruby On Rails,Paper Trail Gem,我想跟踪存储的更改并将其存储在一个storage\u versions表中,该表有一个列storage\u type来存储被修改的存储类型。我试着这样做: class Storage < ApplicationRecord has_paper_trail(meta: {storage_type: :storage_type}), class_name: 'StorageVersion' //additional methods here end class StorageVers

我想跟踪存储的更改并将其存储在一个storage\u versions表中,该表有一个列storage\u type来存储被修改的存储类型。我试着这样做:

class Storage < ApplicationRecord
    has_paper_trail(meta: {storage_type: :storage_type}), class_name: 'StorageVersion'
//additional methods here
end
class StorageVersion < PaperTrail::Version
    self.table_name = 'storage_versions'
end

就像jemonsanto说的。谢谢你@jemonsanto

它无法通过的原因可能有很多:

您尚未发布架构,因此请检查是否声明了存储类型

如果没有
versions
表,那么它肯定会崩溃。 您可以通过根据将基类声明为抽象类来解决这个问题

其次,

您的类声明需要修复,因为它位于文件夹中,您需要将其添加到模块
PaperTrail
。因此,您的类应该是,
PaperTrail::StorageVersion

如果您不想这样做,您可以从子文件夹中删除该类,让它驻留在
models/

您对
的方法声明有一些不可靠。您已在参数中排除类名。还注意到,您已将类放入
app/models/paper\u trail/storage\u version
,需要在方法声明中指定该路径


有\u paper\u trail类\u name:'PaperTrail::StorageVersion',meta:{storage\u type:storage\u type}

对于这个不完整的问题,非常抱歉。通过将storage_version.rb移到paper_trail文件夹之外并更改storage.rb中has_paper_trail的声明,可以解决此问题
has_paper_trail class_name: 'StorageVersion', meta: { storage_type: :storage_type }