2012-11-29 14 views
8

Wie listen Sie alle Autoload-Pfade in Rails 3 auf?So listen Sie alle Autoload-Pfade in Rails 3 auf

In Rails-Konsole, wenn ich dies tun, listet es nur die benutzerdefinierten Pfade zu den Config hinzugefügt:

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

Antwort

16

Update: bitte Lauras siehe Antwort mit Active :: Dependencies.autoload_paths unten. Ich habe diese Antwort hier als alternative Methode hinterlassen.

In Rails::Engine, die in der Rails-Anwendung des Moduls enthalten ist, gibt es die folgende Methode:

def _all_autoload_paths 
    @_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq 
end 

ja, könnten Sie entweder tun:

(MyRailsApp::Application.config.autoload_paths + MyRailsApp::Application.config.eager_load_paths + MyRailsApp::Application.config.autoload_once_paths).uniq 

oder:

[:autoload_paths, :eager_load_paths, :autoload_once_paths].collect{|m|MyRailsApp::Application.config.send(m)}.flatten.uniq 

oder einfach:

MyRailsApp::Application._all_autoload_paths 

Das Standarder in Rails 3.2.9 ist:

["/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"] 

Dies sollte alle automatisch geladen Pfade enthält, die von anderen Edelsteinen und benutzerdefinierten Lastpfaden hinzugefügt wurde.

Verwandte Themen