ActiveStorage::PurgeJob:Class 的未定义方法“discard_on”(NoMethodError)

undefined method `discard_on' for ActiveStorage::PurgeJob:Class (NoMethodError)

最近从 4.2 升级到 Rails 5.2 后,我正在尝试测试生产,但每次启动时都会出现这种情况。

Traceback (most recent call last):
        55: from script/rails:6:in `<main>'
        54: from script/rails:6:in `require'
        53: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/commands.rb:18:in `<top (required)>'
        52: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/command.rb:46:in `invoke'
        51: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/command/base.rb:69:in `perform'
        50: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        49: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        48: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        47: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/commands/console/console_command.rb:95:in `perform'
        46: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
        45: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/command/actions.rb:28:in `require_environment!'
        44: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/application.rb:337:in `require_environment!'
        43: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
        42: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'
        41: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'
        40: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
        39: from /home/deploy/DSM/config/environment.rb:5:in `<top (required)>'
        38: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/railtie.rb:190:in `method_missing'
        37: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/railtie.rb:190:in `public_send'
        36: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/application.rb:361:in `initialize!'
        35: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/initializable.rb:60:in `run_initializers'
        34: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
        33: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
        32: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
        31: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
        30: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
        29: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
        28: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
        27: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        26: from /home/deploy/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
        25: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
        24: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/initializable.rb:32:in `run'
        23: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/initializable.rb:32:in `instance_exec'
        22: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
        21: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/application/finisher.rb:69:in `each'
        20: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:356:in `eager_load!'
        19: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:475:in `eager_load!'
        18: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:475:in `each'
        17: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:477:in `block in eager_load!'
        16: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:477:in `each'
        15: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/railties-5.2.4.3/lib/rails/engine.rb:478:in `block (2 levels) in eager_load!'
        14: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:246:in `require_dependency'
        13: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:334:in `depend_on'
        12: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:356:in `require_or_load'
        11: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:37:in `load_interlock'
        10: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies/interlock.rb:13:in `loading'
         9: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
         8: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
         7: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:37:in `block in load_interlock'
         6: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:378:in `block in require_or_load'
         5: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
         4: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'
         3: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'
         2: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'
         1: from /home/deploy/.rvm/gems/ruby-2.5.1/gems/activestorage-5.2.4.3/app/jobs/active_storage/purge_job.rb:4:in `<top (required)>'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/activestorage-5.2.4.3/app/jobs/active_storage/purge_job.rb:5:in `<class:PurgeJob>': undefined method `discard_on' for ActiveStorage::PurgeJob:Class (NoMethodError)

在 development/test 中不会发生以下情况,或者在 production.rb 中禁用 eager_load,这是有道理的。

我正在使用 rvm(2.5.1、2.5.0、2.6.5)尝试了所有三个。 rails-v:Rails5.2.4.3

这些是内置方法,所以我不确定 TS/resolve 的最佳方法。

所以我想通了。

我曾尝试去 rails 6,但需要更改的地方太多了。这样做时,我的 rvm gems 目录中有 activejob_backport-0.0.3,删除后,问题不再发生。