database.yml在Rails 4中的ActiveRecord中加载了哪里?

ActiveRecord代码库中的哪一行(或方法)是否加载了Rails应用程序的config / database.yml? (我特别关注4.0.5,但是如果有人有关于= = 4.0.5的任何信息,那会很有启发性)?

它位于Railties中,特别是在第101-116行(适用于Rails 4.0.6)的文件railties/lib/rails/application/configuration.rb中:

https://github.com/rails/rails/blob/4-0-6/railties/lib/rails/application/configuration.rb#L101-L116

 # Loads and returns the configuration of the database. def database_configuration yaml = paths["config/database"].first if File.exist?(yaml) require "erb" YAML.load ERB.new(IO.read(yaml)).result elsif ENV['DATABASE_URL'] nil else raise "Could not load database configuration. No such file - #{yaml}" end rescue Psych::SyntaxError => e raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ "Error: #{e.message}" end 

在Rails 4.0.6中,“database.yml” -File的位置在railties配置中设置:

 paths.add "config/database", with: "config/database.yml" 

然后加载此文件(如前面的答案建议) 下面几行 :

 YAML.load ERB.new(IO.read(yaml)).result