From 4bdaf95b82a1358b11bbfb857a1ac2790136a4ef Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Thu, 21 Feb 2013 01:13:10 +1100 Subject: standardize database_configuration to a hash make connection_url_to_hash a class method This als prevents loading database.yml if it doesn't exist but DATABASE_URL does --- railties/lib/rails/application/configuration.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 2c7ddd86e7..1b88b834c7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -101,8 +101,12 @@ module Rails # contents of the file are processed via ERB before being sent through # YAML::load. def database_configuration - require 'erb' - YAML.load ERB.new(IO.read(paths["config/database"].first)).result + if ENV['DATABASE_URL'] + {Rails.env => ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.connection_url_to_hash(ENV['DATABASE_URL']).stringify_keys} + else + require 'erb' + YAML.load ERB.new(IO.read(paths["config/database"].first)).result + 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. " \ -- cgit v1.2.3