简体   繁体   English

控制器中无法加载的模块-NameError:未初始化的常量

[英]Cant load module in controller - NameError: uninitialized constant

How can I load my services module if I have this directory and file structure: 如果我具有以下目录和文件结构,如何加载我的服务模块:

MarketShare::Foo in app/services/market_share/foo.rb MarketShare::Foo in app/services/market_share/foo.rb

So I can access this module with rails console (eg: MarketShare::Foo ), but in my controller Report::MarketSharesController in app/controllers/report/market_shares_controller.rb I get this error: 因此,我可以使用rails控制台(例如: MarketShare::Foo )访问此模块,但是在我的控制器Report::MarketSharesControllerapp/controllers/report/market_shares_controller.rb我收到此错误:

NameError: uninitialized constant Report::MarketSharesController::Foo

when I call with MarketShare::Foo . 当我致电MarketShare::Foo

I have insert this path in autoloads too: 我也在自动加载中插入了此路径:

config.autoload_paths.push(Rails.root.join('app/services/market_share')) 

but I got the same error again. 但是我又遇到了同样的错误。

EDITED: Guys, i try stop rails server and stop spring too, but the error persist. 编辑:伙计们,我也尝试停止rails server并停止spring ,但是错误仍然存​​在。

You don't need this configuration: 您不需要此配置:

config.autoload_paths.push(Rails.root.join('app/services/market_share')) config.autoload_paths.push(Rails.root.join( '应用程序/服务/ market_share'))

Try following: 请尝试以下操作:

1- STOP Rails: CRTL + z 1-停止导轨:CRTL + z

2- STOP Spring: bin/spring stop 2-STOP弹簧:料仓/弹簧停止

3- START Rails: bin/rails s 3- START滑轨:垃圾桶/滑轨

Reload your app 重新加载您的应用

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

相关问题 控制器模块中的未初始化常量 - Uninitialized constant in module in controller 未初始化的常量Sorcery :: TestHelpers :: Rails :: Controller(NameError) - uninitialized constant Sorcery::TestHelpers::Rails::Controller (NameError) “ <module:ActiveRecord> &#39;:未初始化的常量CarrierWave :: Mount(NameError) - '<module:ActiveRecord>': uninitialized constant CarrierWave::Mount (NameError) 包含模块时未初始化的常量(NameError) - uninitialized constant (NameError) while including module 红宝石模块NameError:未初始化的常量错误 - ruby module NameError: uninitialized constant error Puma:无法加载应用程序:NameError:未初始化的常量 - Puma: Unable to load application: NameError: uninitialized constant Rails NameError:初始加载时未初始化的常量 - Rails NameError: uninitialized constant on initial load `load_missing_constant&#39;:未初始化的常量AuthenticatedTestHelper(NameError) - `load_missing_constant': uninitialized constant AuthenticatedTestHelper (NameError) NameError:rspec控制器测试时控制器中的未初始化常量 - NameError: uninitialized constant in controller while rspec controller testing NameError:未初始化的常量项 - NameError: uninitialized constant Item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM