[英]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::MarketSharesController
在app/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.