简体   繁体   English

未初始化常量 ActiveRecord::Raltie::ActiveRecord

[英]uninitialized constant ActiveRecord::Railtie::ActiveRecord

While upgrading from Ruby 2.6.6 to Ruby 3.1.3 and from Rails 5.2.6 to Rails 6.0.6, I made sure that I followed and incorporated all the changes between these 2 rails versions.在从 Ruby 2.6.6 升级到 Ruby 3.1.3 以及从 Rails 5.2.6 升级到 Rails 6.0.6 时,我确保遵循并合并了这两个 Rails 版本之间的所有更改。 I am not sure why I am getting the following error.我不确定为什么会收到以下错误。

mw@2981eebea820:/workspaces/mw$ bundle exec rspec spec
DEPRECATION WARNING: Logger don't need to call #after_initialize directly anymore. It will be deprecated without replacement in Rails 6.1. (called from new at /workspaces/mw/config/application.rb:53)

An error occurred while loading ./spec/controllers/basic_controller_spec.rb.
Failure/Error: require 'rspec/rails'

NameError:
  uninitialized constant ActiveRecord::Railtie::ActiveRecord

          include ActiveRecord::Railties::ControllerRuntime
                  ^^^^^^^^^^^^
# /usr/local/bundle/gems/activerecord-6.0.6/lib/active_record/railtie.rb:209:in `block (2 levels) in <class:Railtie>'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:51:in `each'
# /usr/local/bundle/gems/activesupport-6.0.6/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:269:in `<class:Base>'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:166:in `<module:ActionController>'
# /usr/local/bundle/gems/actionpack-6.0.6/lib/action_controller/base.rb:7:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:13:in `<class:TestCase>'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:12:in `<module:ActionView>'
# /usr/local/bundle/gems/actionview-6.0.6/lib/action_view/test_case.rb:10:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/spec_helper.rb:5:in `<main>'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
# /usr/local/bundle/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# ./spec/rails_helper.rb:10:in `<top (required)>'
# ./spec/controllers/basic_controller_spec.rb:1:in `require'
# ./spec/controllers/basic_controller_spec.rb:1:in `<top (required)>'

Did you make any huge jumps between Rubies?你有没有在红宝石之间做出任何巨大的跳跃? You should have moved to 2.7 first, then when that works okay, you go to 3.0 and so on.你应该先移动到 2.7,然后当它工作正常时,你 go 到 3.0 等等。 That was what I did after a huge jump broke and I did not even know where the problem is coming from.这就是我在一次巨大的跳跃失败后所做的,我什至不知道问题出在哪里。 I rolled back and made little jumps and it all worked out.我向后翻滚并小幅度跳跃,一切都成功了。 I understand this is not a code solution but I hope it helps anyway.我知道这不是代码解决方案,但我希望它能有所帮助。

So, it turned out that the project did not have any dependency on the database so require "active_record/railtie" was dropped in the application.rb but there was an explicit call in the spec/rails_helper.rb that was referring to ActiveRecord - Object.send(:remove_const, :ActiveRecord) .因此,事实证明该项目对数据库没有任何依赖性,因此require "active_record/railtie"在 application.rb 中被删除,但在spec/rails_helper.rb中有一个显式调用,它指的是 ActiveRecord - Object.send(:remove_const, :ActiveRecord) After dropping that call, it started working.挂断电话后,它开始工作。 I am not sure why this was working previously in the first place.我不确定为什么这首先会起作用。 Thanks for all the help!感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM