ruby `const_get ':未初始化常数

bfrts1fy  于 2023-05-17  发布在  Ruby
关注(0)|答案(1)|浏览(82)

我把Ruby版本从2.5.7升级到2.7.5,把Rails从5.2.4.4升级到6.1.5。
我得到了这个错误

/home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:287:in `const_get': uninitialized constant Web::Shared::CommercialBeyondBannerHelper (NameError)

web/shared/_commercial_beyond_banner_helper.rb

# frozen_string_literal: true

module Web::Shared
  module CommercialBeyondBannerHelper

    def function
      # something here
    end

  end
end

这是完整的堆栈跟踪:

Traceback (most recent call last):
    81: from bin/rails:9:in `<main>'
    80: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    79: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    78: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands.rb:18:in `<main>'
    77: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/command.rb:48:in `invoke'
    76: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/command/base.rb:69:in `perform'
    75: from /home/rth/.rvm/gems/ruby-2.7.5/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    74: from /home/rth/.rvm/gems/ruby-2.7.5/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    73: from /home/rth/.rvm/gems/ruby-2.7.5/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    72: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands/server/server_command.rb:135:in `perform'
    71: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands/server/server_command.rb:135:in `tap'
    70: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands/server/server_command.rb:144:in `block in perform'
    69: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands/server/server_command.rb:37:in `start'
    68: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
    67: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/server.rb:422:in `wrapped_app'
    66: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/server.rb:249:in `app'
    65: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/server.rb:349:in `build_app_and_options_from_config'
    64: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/builder.rb:66:in `parse_file'
    63: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/builder.rb:105:in `load_file'
    62: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/builder.rb:116:in `new_from_string'
    61: from /home/rth/.rvm/gems/ruby-2.7.5/gems/rack-2.2.7/lib/rack/builder.rb:116:in `eval'
    60: from config.ru:3:in `block in <main>'
    59: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    58: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    57: from /home/rth/khoi/rails/burpple-on-rails/config/environment.rb:5:in `<main>'
    56: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/railtie.rb:207:in `method_missing'
    55: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/railtie.rb:207:in `public_send'
    54: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/application.rb:391:in `initialize!'
    53: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:60:in `run_initializers'
    52: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
    51: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
    50: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
    49: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `call'
    48: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:347:in `each'
    47: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
    46: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:415:in `each_strongly_connected_component_from'
    45: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:415:in `call'
    44: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:50:in `tsort_each_child'
    43: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:50:in `each'
    42: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    41: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
    40: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    39: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    38: from /home/rth/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
    37: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:61:in `block in run_initializers'
    36: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:32:in `run'
    35: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/initializable.rb:32:in `instance_exec'
    34: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/engine.rb:633:in `block in <class:Engine>'
    33: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/engine.rb:633:in `each'
    32: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
    31: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/engine.rb:680:in `load_config_initializer'
    30: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/notifications.rb:205:in `instrument'
    29: from /home/rth/.rvm/gems/ruby-2.7.5/gems/railties-6.1.7.3/lib/rails/engine.rb:681:in `block in load_config_initializer'
28: from /home/rth/khoi/rails/burpple-on-rails/config/initializers/active_admin.rb:266:in `<main>'
    27: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    26: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    25: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activeadmin-2.13.1/lib/active_admin/base_controller.rb:2:in `<main>'
    24: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    23: from /home/rth/.rvm/gems/ruby-2.7.5/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    22: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activeadmin-2.13.1/lib/active_admin/base_controller/authorization.rb:2:in `<main>'
    21: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activeadmin-2.13.1/lib/active_admin/base_controller/authorization.rb:3:in `<module:ActiveAdmin>'
    20: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/dependencies/interlock.rb:13:in `loading'
    19: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    18: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    17: from /home/rth/.rvm/gems/ruby-2.7.5/gems/inherited_resources-1.13.1/app/controllers/inherited_resources/base.rb:1:in `<main>'
    16: from /home/rth/.rvm/gems/ruby-2.7.5/gems/inherited_resources-1.13.1/app/controllers/inherited_resources/base.rb:11:in `<module:InheritedResources>'
    15: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/dependencies/interlock.rb:13:in `loading'
    14: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    13: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    12: from /home/rth/khoi/rails/burpple-on-rails/app/controllers/application_controller.rb:5:in `<main>'
    11: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/action_controller/railties/helpers.rb:19:in `inherited'
    10: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/abstract_controller/helpers.rb:147:in `helper'
     9: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/action_controller/metal/helpers.rb:104:in `modules_for_helpers'
     8: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/abstract_controller/helpers.rb:169:in `modules_for_helpers'
     7: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/abstract_controller/helpers.rb:169:in `map!'
     6: from /home/rth/.rvm/gems/ruby-2.7.5/gems/actionpack-6.1.7.3/lib/abstract_controller/helpers.rb:176:in `block in modules_for_helpers'
     5: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/core_ext/string/inflections.rb:74:in `constantize'
     4: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:283:in `constantize'
     3: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:283:in `inject'
     2: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:283:in `each'
     1: from /home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:287:in `block in constantize'
/home/rth/.rvm/gems/ruby-2.7.5/gems/activesupport-6.1.7.3/lib/active_support/inflector/methods.rb:287:in `const_get': uninitialized constant Web::Shared::CommercialBeyondBannerHelper (NameError)

它仍然在旧版本中运行良好!你能帮帮我吗!谢谢!

zrfyljdw

zrfyljdw1#

这个错误告诉你一些代码试图使用Web::Shared::CommercialBeyondBannerHelper,但是这个模块还没有初始化,并且因为找不到它而不能自动加载。
zeitwerk是Rails 6中新的自动加载器,它会尽可能地延迟加载。
上面的链接很好地解释了交换机,并提供了如何找到潜在问题的提示(通过运行bin/rails zeitwerk:check)。
正如@Arctodus所建议的,这通常就像文件名或目录问题一样简单。
zeitwerk希望能够通过目录和文件名来查找常量,并具有一定的灵活性。
您的文件名以下划线开头:web/shared/_commercial_beyond_banner_helper.rb
zeitwerk期望只有视图部分以下划线开头。
如果这个文件是一个view partial,那么在其中定义一个模块就很奇怪了,而在其他地方调用这个模块就更奇怪了。

相关问题