如何在Rails 3中列出所有自动加载路径 [英] How to list all autoload paths in Rails 3

查看:87
本文介绍了如何在Rails 3中列出所有自动加载路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Rails 3中列出所有自动加载路径?

How do you list all of the autoload paths in Rails 3?

在Rails控制台中执行此操作时,它仅列出添加到配置中的自定义路径:

In Rails console when I do this, it only lists the custom paths added to the config:

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

推荐答案

更新:请参阅下面使用ActiveSupport :: Dependencies.autoload_paths的劳拉答案.我把这个答案留在这里作为替代方法.

在Rails应用程序模块中包含的Rails::Engine中,有以下方法:

In Rails::Engine which is included in the Rails application's module, there is the following method:

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

因此,您可以执行以下操作:

So, you could either do:

(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中的默认结果是:

The default result in Rails 3.2.9 is:

["/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和自定义加载路径添加的所有自动加载路径.

This should include all the autoload paths that were added by other gems and custom load paths.

这篇关于如何在Rails 3中列出所有自动加载路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆