在Rails 4的ActiveRecord中,database.yml在哪里加载? [英] where does database.yml get loaded in ActiveRecord in Rails 4?

查看:131
本文介绍了在Rails 4的ActiveRecord中,database.yml在哪里加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails应用程序的config / database.yml是否在ActiveRecord代码库中的哪一行(或方法)被加载? (我正在专门查看4.0.5,但是如果有人对> = 4.0.5有任何了解,那将很有启发性)?

What line (or method) in the ActiveRecord codebase does the config/database.yml for a Rails application get loaded? (I'm looking at 4.0.5 specifically, but if anyone has any information on >=4.0.5, that would be illuminating)?

推荐答案

它位于Railties中,特别是在 railties / lib / rails / application / configuration文件中。 rb 在101–116行中(对于Rails 4.0.5):

It's inside the Railties, specifically in the file railties/lib/rails/application/configuration.rb in lines 101–116 (for Rails 4.0.5):

https://github.com/rails/rails/blob/v4.0.5/ 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的ActiveRecord中,database.yml在哪里加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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