ArgumentError:升级 Rails 6.1.3 时出现错误数量的参数错误

Posted

技术标签:

【中文标题】ArgumentError:升级 Rails 6.1.3 时出现错误数量的参数错误【英文标题】:ArgumentError: Wrong Number of Arguments Errors when upgrading Rails 6.1.3 【发布时间】:2021-07-08 23:58:58 【问题描述】:

在 mimemagic 惨败之后,我最近将 Rails 6.0.3.5 应用升级到 6.1.3。

现在,我看到渲染视图后发生的这个有趣的问题,这很奇怪。我该如何调试?该应用使用 Ruby 2.7.1

这是完整的堆栈跟踪

[31a95c67-7597-4856-9dfc-e813bb0d760a]   Rendered layout layouts/application.html.erb (Duration: 5001.5ms | Allocations: 119937)
[31a95c67-7597-4856-9dfc-e813bb0d760a] Completed 200 OK in 5572ms (Views: 5005.9ms | ActiveRecord: 23.5ms | Allocations: 196152)
[31a95c67-7597-4856-9dfc-e813bb0d760a]
ArgumentError: wrong number of arguments (given 2, expected 3)
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionview-6.1.3.1/lib/action_view/base.rb:230:in `initialize'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `new'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `render'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/web-console-3.7.0/lib/web_console/middleware.rb:37:in `block in call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/railties-6.1.3.1/lib/rails/rack/logger.rb:37:in `call_app'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/railties-6.1.3.1/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/activesupport-6.1.3.1/lib/active_support/tagged_logging.rb:99:in `block in tagged'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/activesupport-6.1.3.1/lib/active_support/tagged_logging.rb:37:in `tagged'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/activesupport-6.1.3.1/lib/active_support/tagged_logging.rb:99:in `tagged'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/railties-6.1.3.1/lib/rails/rack/logger.rb:26:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/request_id.rb:26:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/activesupport-6.1.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/static.rb:24:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/actionpack-6.1.3.1/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/webpacker-5.2.1/lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/railties-6.1.3.1/lib/rails/engine.rb:539:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/configuration.rb:247:in `call'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/request.rb:76:in `block in handle_request'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/thread_pool.rb:337:in `with_force_shutdown'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/request.rb:75:in `handle_request'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/server.rb:431:in `process_client'
    from /Users/aurs/.rvm/gems/ruby-2.7.1/gems/puma-5.2.1/lib/puma/thread_pool.rb:145:in `block in spawn_thread'

【问题讨论】:

web-console gem 与 Rails 6.1 中断,升级修复了它。 【参考方案1】:

web-console gem 与 Rails 6.1 中断,升级到 4.1.0 修复了错误。

【讨论】:

在我的情况下是另一个 gem,对于在升级 rails 时遇到问题的任何人,我建议使用此工具检查兼容性railsbump.org

以上是关于ArgumentError:升级 Rails 6.1.3 时出现错误数量的参数错误的主要内容,如果未能解决你的问题,请参考以下文章

部署 Ruby on Rails 6 - AWS Elastic Beanstalk - Docker: ArgumentError: Missing `secret_key_base`

Rails 执行迁移 ArgumentError

Rails::MailersController#preview 中的 ArgumentError

Rails Draper 的装饰器导致 ArgumentError

Rails - 使用ActiveRecord :: Enum时的ArgumentError

Rails 4 引发 ArgumentError(参数数量错误(2 对 1)):通过 AJAX POST 更新时