Rails Heroku 部署中的 PaperTrail 版本名称错误

Rails PaperTrail Version NameError on Heroku Deployment

我正在尝试 运行 迁移 运行 是一个 rake 任务,它会破坏 paper_trail gem 在 Rails 中生成的旧版本数据5 应用程序。迁移似乎在开发环境中本地工作,但在推送到 Heroku 时部署失败。这是 Heroku 上的错误:

...

Deleting records for table: versions...
rake aborted!
NameError: uninitialized constant Version

...

config/initializers/paper_trail.rb

PaperTrail.config.track_associations = false
PaperTrail.config.version_limit = 100

require 'paper_trail/frameworks/active_record/models/paper_trail/version'
require Rails.root.join('./app/controllers/concerns/paper_trail_version_search.rb')

module PaperTrail
  class Version < ActiveRecord::Base    
    extend PaperTrailVersionSearch
  end
end

db/migrate/20170530151849_remove_old_versions_table_data.rb

class RemoveOldVersionsTableData < ActiveRecord::Migration[5.0]
  def change
    Rake::Task.clear
    <App Name Redacted>::Application.load_tasks

    Rake::Task["remove_old_versions_table_data"].invoke
  end
end

lib/tasks/remove_old_versions_table_data.rake

desc 'remove excessive and unnecessary versions data created prior to implementation of version limits'

task remove_old_versions_table_data: :environment do
  PaperTrail::Version.where("created_at <= ?", "2017-06-12").delete_all
end

有什么想法吗?

给出错误信息:

NameError: uninitialized constant Version

可能是因为您在初始化程序中重新打开了 PaperTrail::Version class。这 不再是重新打开 Version 的推荐方式。 请参阅 changelog for version 4.0.0:

Using a Rails initializer to reopen PaperTrail::Version or otherwise extend PaperTrail is no longer recommended. An alternative is described in the readme. See https://github.com/airblade/paper_trail/pull/557 and https://github.com/airblade/paper_trail/pull/492.

最近,我们建议人们在 app/models/paper_trail/version.rb 重新营业。

如果您在初始化程序中重新打开,Version 可能尚未定义。我不记得为什么。某事,某事,rails 启动顺序,某事,某事。