Heroku部署中的Rails PaperTrail版本NameError

时间:2017-07-10 16:07:54

标签: ruby-on-rails ruby heroku ruby-on-rails-5 paper-trail-gem

我尝试运行运行rake任务的迁移,该任务会破坏Rails 5应用中使用paper_trail gem生成的旧版本数据。迁移似乎在dev env中本地工作,但是在推送到Heroku时它没有部署。这是Heroku的错误:

...

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

...

配置/初始化/ 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

分贝/迁移/ 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 /任务/ 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

有什么想法会发生什么?

1 个答案:

答案 0 :(得分:1)

给出错误消息:

NameError: uninitialized constant Version

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

  

不再推荐使用Rails初始化程序重新打开PaperTrail :: Version或以其他方式扩展PaperTrail。自述文件中描述了一种替代方案。请参阅https://github.com/airblade/paper_trail/pull/557https://github.com/airblade/paper_trail/pull/492

现在,我们建议人们在app/models/paper_trail/version.rb重新开启。

如果您在初始值设定项中重新打开,则可能尚未定义Version。我不记得为什么。东西,东西,铁路开机订单,东西,等等。