ruby – 在Rails 4中的ActiveRecord中加载database.yml的位置?
发布时间:2020-12-17 04:01:51 所属栏目:百科 来源:网络整理
导读:ActiveRecord代码库中的哪一行(或方法)是否加载了Rails应用程序的config / database.yml? (我具体看4.0.5,但是如果有人有关于 = 4.0.5的任何信息,那会很有启发性)? 解决方法 它位于Railties中,特别是在第101-116行的文件railties / lib / rails / applicat
ActiveRecord代码库中的哪一行(或方法)是否加载了Rails应用程序的config /
database.yml? (我具体看4.0.5,但是如果有人有关于> = 4.0.5的任何信息,那会很有启发性)?
解决方法
它位于Railties中,特别是在第101-116行的文件railties / lib / rails / application / configuration.rb中(对于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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |