最好的方法加载模块/类从Rails 3中的lib文件夹? [英] Best way to load module/class from lib folder in Rails 3?
本文介绍了最好的方法加载模块/类从Rails 3中的lib文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于最新的Rails 3版本不是从lib自动加载模块和类,
什么是最好的加载方式?
Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them?
从github:
A few changes were done in this commit:
Do not autoload code in *lib* for applications (now you need to explicitly
require them). This makes an application behave closer to an engine
(code in lib is still autoloaded for plugins);
推荐答案
自Rails 2.3.9开始 ,在 config / application.rb
中有一个设置,您可以在其中指定包含要自动加载的文件的目录。
As of Rails 2.3.9, there is a setting in config/application.rb
in which you can specify directories that contain files you want autoloaded.
从application.rb:
From application.rb:
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
这篇关于最好的方法加载模块/类从Rails 3中的lib文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文