Trong database.yml tôi, tôi có:ray database.yml không chấp nhận ERB
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'] %>
Tuy nhiên, nó không đọc phần ERB khi thực sự khởi động puma:
/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)
mà làm không ý nghĩa, vì trong mã Rails tải cấu hình cơ sở dữ liệu:
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
(lấy từ mã ổn định Rails 4.2, tôi đang chạy 4.2.1)
Tôi hoàn toàn bối rối vì sao điều này không hiệu quả, bất kỳ ý tưởng nào?
Tôi đã sử dụng một phiên bản cũ hơn (2.11.3), đã có vấn đề. Puma nâng cấp, không thay đổi. –
Chris, tôi đã chỉnh sửa câu trả lời của mình, không biết liệu bạn có được thông báo về bản chỉnh sửa hay không, hy vọng bạn sẽ được thông báo về nhận xét này và câu trả lời mới sẽ giải quyết được vấn đề của bạn. – user155995
Điều đó thực sự đã sửa nó! Cảm ơn một người đàn ông bó, đẹp bắt. –