我正在开发一个使用 PostgreSQL 的 Rails 项目,我想将数据库登录详细信息存储在一个文件中,并使用 rbenv-vars 通过环境变量访问它们。我正在运行 Ubuntu 16.10。
考虑以下文件:
pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
数据库.yml
default: &default
adapter: postgresql
encoding: unicode
host: localhost
pool: 5
username: consul
password: <% ENV['CONSUL_DATABASE_PASSWORD'] %>
.rbenv-变量
SECRET_KEY_BASE=(secret key)
CONSUL_DATABASE_PASSWORD=(database password)
当我尝试使用 rake db:create
命令为项目创建数据库时,出现此错误:
fe_sendauth: no password supplied
我尝试以明文形式存储密码并且它有效,但正如你想象的那样,我不想那样做。
最佳答案
将行改为
password: <%= ENV['CONSUL_DATABASE_PASSWORD'] %>
<% %>
只是评估内容而
<%= %>
计算内容并将其插入到标记的位置
有关 erb 标签的更多详细信息,请参阅此答案 What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
关于ruby-on-rails - Rails + PostgreSQL + rbenv-vars : fe_sendauth: no password supplied using environment variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44899011/