小编典典

从 Rails 3 中的 lib 文件夹加载模块/类的最佳方法?

all

由于最新的 Rails 3 版本不再从 lib 中自动加载模块和类,那么加载它们的最佳方式是什么?

来自 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);


阅读 62

收藏
2022-05-06

共1个答案

小编典典

从 Rails 2.3.9开始,config/application.rb您可以在其中指定包含要自动加载的文件的目录。

来自 application.rb:

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
2022-05-06