9

In meinem database.yml, ich habe:Schienen database.yml nicht ERB Annahme

staging: 
    adapter: <%= ENV['DATABASE_ADAPTER'] %> 
    encoding: <%= ENV['DATABASE_ENCODING'] %> 
    database: <%= ENV['DATABASE'] %> 
    host: <%= ENV['DATABASE_HOST'] %> 
    port: <%= ENV['DATABASE_PORT'].to_i %> 
    pool: <%= ENV['DATABASE_POOL'].to_i %> 
    username: <%= ENV['DATABASE_USERNAME'] %> 
    password: <%= ENV['DATABASE_PASSWORD'] %> 

Es ist jedoch nicht das ERB Teil liest, wenn tatsächlich puma Booten:

/usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in 
`require': Could not load 'active_record/connection_adapters/<%= ENV['DATABASE_ADAPTER'] %>_adapter'. 
Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' 
add the necessary adapter gem to the Gemfile. (LoadError) 

das macht keine Sinn, da in dem Code Rails die Datenbankkonfiguration zu laden:

def database_configuration 
    yaml = Pathname.new(paths["config/database"].existent.first || "") 

    config = if yaml.exist? 
     require "yaml" 
     require "erb" 
     YAML.load(ERB.new(yaml.read).result) || {} 
    elsif ENV['DATABASE_URL'] 
     # Value from ENV['DATABASE_URL'] is set to default database connection 
     # by Active Record. 
     {} 
    else 
     raise "Could not load database configuration. No such file - #{yaml}" 
    end 

    config 
    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}" 
    rescue => e 
    raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace 
    end 

(genommen von den Schienen 4.2 stabiler Code, ich bin mit 4.2.1)

Ich bin absolut verblüfft, warum das nicht funktioniert, irgendwelche Ideen?

Antwort

19

Ich habe gerade das gleiche erlebt, und stieß auf Ihre Post. Ich hatte ein Tutorial verfolgt, die mir eine puma.conf-Datei erstellen hatte, die den Code unten enthalten:

ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env]) 

ich auf die folgende geändert, und alles funktionierte wie erwartet:

require 'erb' 
ActiveRecord::Base.establish_connection(YAML.load(ERB.new(File.read("#{app_dir}/config/database.yml")).result)[rails_env]) 
+0

Ich war mit ein ältere Version (2.11.3), hatte das Problem. Verbesserter Puma, keine Veränderung. –

+0

Chris, ich habe meine Antwort bearbeitet, weiß nicht, ob Sie über die Bearbeitung informiert wurden, hoffentlich werden Sie über diesen Kommentar benachrichtigt und die neue Antwort löst Ihr Problem. – user155995

+0

Das hat es tatsächlich behoben! Danke, ein bunter Mann, schöner Fang. –

Verwandte Themen