2012-11-29 23 views
8

如何列出Rails 3中的所有自動加載路徑?如何列出Rails 3中的所有自動加載路徑

在Rails控制檯當我這樣做,它只是列出添加到配置自定義路徑:

$ rails c 
Loading development environment (Rails 3.2.9) 
1.9.3p194 :001 > MyRailsApp::Application.config.autoload_paths 
=> [] 

回答

16

更新:請通過下面的ActiveSupport :: Dependencies.autoload_paths看到勞拉的答案。我在這裏留下了這個答案作爲替代方法。

Rails::Engine其中包括Rails應用程序的模塊中,有以下方法:

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 

在導軌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"] 

這應包括由其他的寶石和定製負載路徑添加的所有自動加載路徑。

相關問題