Reputation: 145
I created rails config/master.key and config/credentials.yml.enc via rails credentials:edit command
on rails console i'm able to fetch values but when i run rake db:migrate, i get this error:
invalid port number: "Rails.application.credentials.development[:port]"
Couldn't create 'Rails.application.credentials.development[:database]' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: invalid port number: "Rails.application.credentials.development[:port]"
/home/ec2-user/.rvm/gems/ruby-2.6.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/home/ec2-user/.rvm/gems/ruby-2.6.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/home/ec2-user/.rvm/gems/ruby-2.6.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/home/ec2-user/.rvm/gems/ruby-2.6.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
#config/environments/development.rb
config.require_master_key = true
#config/credentials.yml.enc
development:
database: xxxxxxxx
username: yyyyyyyy
password: zzzzzzzz
host: aaaaaaa.com
port: 1234
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: 1234567890
#config/database.yml
default: &default
adapter: postgresql
encoding: utf8
database: Rails.application.credentials.development[:database]
username: Rails.application.credentials.development[:username]
password: Rails.application.credentials.development[:password]
host: Rails.application.credentials.development[:host]
port: Rails.application.credentials.development[:port]
development:
<<: *default
Upvotes: 2
Views: 4103
Reputation: 15298
It looks that problem in syntax
You need to use interpolation like this:
database: <%= Rails.application.credentials.development[:database] %>
username: <%= Rails.application.credentials.development[:username] %>
password: <%= Rails.application.credentials.development[:password] %>
host: <%= Rails.application.credentials.development[:host] %>
port: <%=Rails.application.credentials.development[:port] %>
Upvotes: 9