Rails 4.2无法读取Database.yml的环境变量 [英] Rails 4.2 not reading Environment Variables for Database.yml

查看:49
本文介绍了Rails 4.2无法读取Database.yml的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的database.yml文件似乎未正确拾取环境变量.当我直接输入密码时,没有任何问题,因此我知道这不是密码问题.我还重新启动了服务器.

My database.yml file does not seem to be picking up the environment variable correctly. When I put the password in directly, there are no issues, so I know it's not a password problem. I've also restarted the server.

此外,当我在服务器上启动IRB并输入ENV ["DB_PASSWORD"时,它会返回:

Also, when I launch IRB on the server and type in ENV["DB_PASSWORD" it is returned:

    2.2.0 :001 > ENV["DB_PASSWORD"]
 => "tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc"

database.yml

database.yml

production:
  database: myapp
  username: root
  password: <%= ENV["DB_PASSWORD"] %>
  host: localhost
  adapter: mysql2
  port: 3306
  pool: 15
  timeout: 5000

.bashrc

export MYSQL_DB=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc

推荐答案

您可以在.profile中设置变量,因为它会在每次重新引导服务器时加载.

You can set variable in .profile because it will load every time while you will reboot server.

您可以通过以下步骤添加:

You can add with following step:

打开 sudo nano〜/.profile

然后添加变量

export DB_PASSWORD=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc

然后使用以下方式重新加载配置文件

Then reload profile with

. ~/.profile

这将是可行的.

这篇关于Rails 4.2无法读取Database.yml的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆