简体   繁体   English

设置新的Rails环境变量

[英]Set new rails environment variables

This is probably a easy question but cant seem to find a straight answer. 这可能是一个简单的问题,但似乎找不到直接的答案。 I'm trying to set up a mailer and config the smtp settings and I was wondering how do you set new environment variables for 我正在尝试设置一个邮件程序并配置smtp设置,我想知道如何为它设置新的环境变量

:user_name      => ENV['GMAIL_USERNAME'],
:password       => ENV['GMAIL_PASSWORD']

Thanks for the help. 谢谢您的帮助。

You can set them up and keep them secret using the Figaro Gem 您可以使用Figaro Gem进行设置并将其保密

Add it to your Gemfile and bundle . 将其添加到您的Gemfilebundle Then install Figaro: 然后安装Figaro:

bundle exec figaro install

Once it's installed, you'll have a new file called application.yml in your config folder 安装完成后,您的config文件夹中将有一个名为application.yml的新文件。

You can create environment variables there and they're ignored by Git so your secrets won't get published. 您可以在此处创建环境变量,而Git会忽略它们,因此不会泄露您的秘密。

You can set different variables for different environments if you want. 您可以根据需要为不同的环境设置不同的变量。

development:
  GMAIL_USERNAME: 'yourname@gmail.com'
  GMAIL_PASSWORD: notaRE41p4ssw0rD

production:
  GMAIL_USERNAME: 'yourproductionname@gmail.com'
  GMAIL_PASSWORD: notaRE41p4ssw0rD317h3R

To push them to Heroku: 要将其推送到Heroku:

$ figaro heroku:set -e production

Have a look at the dotenv gem as well. 看看dotenv宝石 Figaro seems to be poorly maintained at the moment. Figaro目前似乎保养不佳。

Another option beside accepted answer, for heroku setting environment variabel can be setup using heroku terminal command as follow 除了可接受的答案之外,还有另一个选项,对于heroku设置环境,可以使用heroku terminal命令如下设置variabel:

heroku config:set GMAIL_USERNAME=******* 
heroku config:set GMAIL_PASSWORD=******

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM