问题描述
我已将我的一个应用程序从Rails 4.2.6升级到Rails 5.0.0. 升级指南说,默认情况下,现在自动在生产环境中禁用自动加载"功能.
I've upgraded one of my apps from Rails 4.2.6 to Rails 5.0.0. The Upgrade Guide says, that the Autoload feature is now disabled in production by default.
现在,由于我在自动加载application.rb
文件的同时加载了所有lib文件,因此在生产服务器上总是会出现错误.
Now I always get an error on my production server since I load all lib files with autoload in the application.rb
file.
module MyApp
class Application < Rails::Application
config.autoload_paths += %W( lib/ )
end
end
现在,我已经将config.enable_dependency_loading
设置为true
,但是我想知道是否有更好的解决方案.在默认情况下,生产中默认禁用自动加载功能是有原因的.
For now, I've set the config.enable_dependency_loading
to true
but I wonder if there is a better solution to this. There must be a reason that Autoloading is disabled in production by default.
推荐答案
由于线程安全性,在生产环境中禁用了自动加载.谢谢@Зелёный的链接.
Autoloading is disabled in the production environment because of thread safety. Thank you to @Зелёный for the link.
我通过按照app目录中的lib
文件夹中来解决此问题. "noreferrer"> Github . app
文件夹中的每个文件夹都会由Rails自动加载.
I solved this problem by storing the lib files in a lib
folder in my app
directory as recommended on Github. Every folder in the app
folder gets loaded by Rails automatically.
这篇关于Rails 5:在生产环境中加载lib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!