Rails 5.1:即使文件存在于自动加载路径中,自动加载路径也不起作用

Rails 5.1: Autoload path is not working even when file present in autoload path

提问人:opensource-developer 提问时间:9/24/2023 更新时间:9/24/2023 访问量:26

问:

我们在项目文件夹根目录中有一个文件夹,在application.rb中也有这个文件夹lib

    config.autoload_paths += %W(#{config.root}/lib)

但我收到一个错误uninitialized constant ActionView::CompiledTemplates::ShopifyApi

当我在 rails 控制台中运行时,这有效

load Rails.root.join('lib/shopify_api.rb')
ShopifyApi::SCOPES

但不在应用程序中。

关于如何解决这个问题的任何帮助都会很棒。

谢谢。

Ruby-on-Rails Ruby-on-Rails-5

评论

0赞 mechnicov 9/24/2023
你试过了吗?::ShopifyApi::SCOPES
0赞 opensource-developer 9/25/2023
是的,那没有用
0赞 mechnicov 9/25/2023
也尝试这个来改变数组config.autoload_paths << "#{root}/lib"
0赞 max 9/26/2023
如果要自动加载代码,请不要将其放在 lib 中。它打败了整个观点。

答: 暂无答案