gpt4 book ai didi

ruby-on-rails - rails 凭据不获取

转载 作者:行者123 更新时间:2023-12-05 08:52:05 28 4
gpt4 key购买 nike

我通过 rails credentials:edit 命令创建了 rails config/master.key 和 config/credentials.yml.enc

在 Rails 控制台上我能够获取值但是当我运行 rake db:migrate 时,我得到这个错误:

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

最佳答案

看起来是语法上的问题

你需要像这样使用插值:

  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] %>

关于ruby-on-rails - rails 凭据不获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57633182/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com