Rails 7 每个文件更改都会引发错误参数数量错误(给定 2,预期 5)
Rails 7 Every File Change Throws Error wrong number of arguments (given 2, expected 5)
最近使用 ruby 3.0.3 设置了新的 Rails 7.0 项目 在使用 bin/dev 启动应用程序之后 在更改任何文件甚至添加空格后都会导致出现此错误,如下所示是日志获取
19:41:24 web.1 | ArgumentError (wrong number of arguments (given 2, expected 5)):
19:41:24 web.1 |
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/instrumenter.rb:62:in `initialize'
19:41:24 web.1 | actionpack (7.0.0) lib/action_dispatch/middleware/server_timing.rb:16:in `new'
19:41:24 web.1 | actionpack (7.0.0) lib/action_dispatch/middleware/server_timing.rb:16:in `block in call'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:225:in `publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:80:in `block in publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:91:in `block in iterate_guarding_exceptions'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:90:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:90:in `iterate_guarding_exceptions'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:80:in `publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications.rb:197:in `publish'
19:41:24 web.1 | activeadmin (12ea37a38525) lib/active_admin/application.rb:115:in `load!'
19:41:24 web.1 | activeadmin (12ea37a38525) lib/active_admin/application.rb:228:in `block (2 levels) in attach_reloader'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `instance_exec'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `block in make_lambda'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:199:in `block (2 levels) in halting'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:687:in `block (2 levels) in default_terminator'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:686:in `catch'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:686:in `block in default_terminator'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:200:in `block in halting'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `block in invoke_before'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `invoke_before'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:106:in `run_callbacks'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:88:in `prepare!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:47:in `block in <class:Reloader>'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `instance_exec'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `block in make_lambda'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:271:in `block in simple'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `block in invoke_after'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `invoke_after'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:108:in `run_callbacks'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:133:in `run'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:129:in `run!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:114:in `run!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:74:in `block in run!'
19:41:24 web.1 | <internal:kernel>:90:in `tap'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:71:in `run!'
尝试在没有 Active Admin 的情况下创建项目。它似乎还不支持 Rails 7。 https://github.com/activeadmin/activeadmin/issues/7196
作为临时解决方案,您可以在 config/environments/development.rb:
中禁用 server_timing
# Enable server timing
- config.server_timing = true
+ # config.server_timing = true
参见https://github.com/activeadmin/activeadmin/issues/7196#issuecomment-1002929616。
感谢@stmpjmpr 的原始答案。只是想提供一点增强的答案。
最近使用 ruby 3.0.3 设置了新的 Rails 7.0 项目 在使用 bin/dev 启动应用程序之后 在更改任何文件甚至添加空格后都会导致出现此错误,如下所示是日志获取
19:41:24 web.1 | ArgumentError (wrong number of arguments (given 2, expected 5)):
19:41:24 web.1 |
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/instrumenter.rb:62:in `initialize'
19:41:24 web.1 | actionpack (7.0.0) lib/action_dispatch/middleware/server_timing.rb:16:in `new'
19:41:24 web.1 | actionpack (7.0.0) lib/action_dispatch/middleware/server_timing.rb:16:in `block in call'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:225:in `publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:80:in `block in publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:91:in `block in iterate_guarding_exceptions'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:90:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:90:in `iterate_guarding_exceptions'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications/fanout.rb:80:in `publish'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/notifications.rb:197:in `publish'
19:41:24 web.1 | activeadmin (12ea37a38525) lib/active_admin/application.rb:115:in `load!'
19:41:24 web.1 | activeadmin (12ea37a38525) lib/active_admin/application.rb:228:in `block (2 levels) in attach_reloader'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `instance_exec'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `block in make_lambda'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:199:in `block (2 levels) in halting'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:687:in `block (2 levels) in default_terminator'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:686:in `catch'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:686:in `block in default_terminator'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:200:in `block in halting'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `block in invoke_before'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:595:in `invoke_before'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:106:in `run_callbacks'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:88:in `prepare!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:47:in `block in <class:Reloader>'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `instance_exec'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:445:in `block in make_lambda'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:271:in `block in simple'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `block in invoke_after'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `each'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:599:in `invoke_after'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/callbacks.rb:108:in `run_callbacks'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:133:in `run'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:129:in `run!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/reloader.rb:114:in `run!'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:74:in `block in run!'
19:41:24 web.1 | <internal:kernel>:90:in `tap'
19:41:24 web.1 | activesupport (7.0.0) lib/active_support/execution_wrapper.rb:71:in `run!'
尝试在没有 Active Admin 的情况下创建项目。它似乎还不支持 Rails 7。 https://github.com/activeadmin/activeadmin/issues/7196
作为临时解决方案,您可以在 config/environments/development.rb:
中禁用server_timing
# Enable server timing
- config.server_timing = true
+ # config.server_timing = true
参见https://github.com/activeadmin/activeadmin/issues/7196#issuecomment-1002929616。
感谢@stmpjmpr 的原始答案。只是想提供一点增强的答案。