Rails 5:在生产中加载 lib 文件 [英] Rails 5: Load lib files in production
问题描述
我已将我的一个应用程序从 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.
我按照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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!