更新:请在下面使用 ActiveSupport::Dependencies.autoload_paths 查看 Laura 的回答。我把这个答案留在这里作为替代方法。
在Rails应用模块中包含的Rails::Engine中,有如下方法:
def _all_autoload_paths
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
end
所以,你可以这样做:
(MyRailsApp::Application.config.autoload_paths + MyRailsApp::Application.config.eager_load_paths + MyRailsApp::Application.config.autoload_once_paths).uniq
或:
[:autoload_paths, :eager_load_paths, :autoload_once_paths].collect{|m|MyRailsApp::Application.config.send(m)}.flatten.uniq
或者只是:
MyRailsApp::Application._all_autoload_paths
Rails 3.2.9 中的默认结果是:
["/path/to/my_rails_app/app/assets", "/path/to/my_rails_app/app/controllers", "/path/to/my_rails_app/app/helpers", "/path/to/my_rails_app/app/mailers", "/path/to/my_rails_app/app/models"]
这应该包括由其他 gem 添加的所有自动加载路径和自定义加载路径。