Rails / Ubuntu在加载时未初始化的命名空间常量

时间:2019-03-18 09:06:51

标签: ruby-on-rails ruby ubuntu rubygems ubuntu-18.04

在Ubuntu上启动Rails应用程序时(通过任何过程,例如控制台,服务器,Rake任务等),我从gems中得到了一个未初始化的常量错误。但是,我可以将完全相同的存储库克隆到OSX上,并且可以正常工作。我显示的错误来自于公寓,但是如果我删除对Core :: Organisation的引用,则该问题只会传播到下一个加载的gem。因此,我认为这与在应用程序中的常量之前加载宝石有关。

我尝试使用

config.eager_load = true
config.enable_dependency_loading = true

但是它没有任何改变。

更新: 我发现仅用“ Organisation”代替“ Core :: Organisation”就可以了。因此,这与命名空间有关。在基本目录中,有一个模块core.rb:

module Core
  def self.table_name_prefix
    'core_'
  end
end

环境:

  • Ubuntu 18.04
  • Ruby 2.5.0
  • 导轨5.2.2

错误跟踪示例:

/var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `block in load_missing_constant': uninitialized constant Core::Organisation (NameError)
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `rescue in load_missing_constant'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:56:in `load_missing_constant'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:285:in `const_get'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:285:in `block in constantize'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `each'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `inject'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/inflector/methods.rb:281:in `constantize'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/core_ext/string/inflections.rb:68:in `constantize'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/adapters/postgresql_adapter.rb:50:in `process_excluded_model'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/adapters/abstract_adapter.rb:105:in `block in process_excluded_models'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/adapters/abstract_adapter.rb:104:in `each'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/adapters/abstract_adapter.rb:104:in `process_excluded_models'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/tenant.rb:18:in `init'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/railtie.rb:34:in `block (2 levels) in <class:Railtie>'
    from /var/lib/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
    from /var/lib/gems/2.5.0/gems/apartment-2.2.0/lib/apartment/railtie.rb:33:in `block in <class:Railtie>'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426:in `instance_exec'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426:in `block in make_lambda'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:606:in `block (2 levels) in default_terminator'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:605:in `catch'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:605:in `block in default_terminator'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:199:in `block in halting'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `block in invoke_before'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `each'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:513:in `invoke_before'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:131:in `run_callbacks'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/reloader.rb:89:in `prepare!'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application/finisher.rb:63:in `block in <module:Finisher>'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /usr/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /usr/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /usr/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /usr/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
    from /var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
    from /home/sellsmartadmin/Sellsmart/config/environment.rb:5:in `<main>'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/lib/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

在此先感谢任何人提供的帮助!

1 个答案:

答案 0 :(得分:0)

我找到了答案!

事实证明,Linux在目录方面比OSX更加混乱。我的命名空间模块位于名为“ Core /”的目录中。当我将其更改为“ core”(全部小写)时,一切都按预期工作。