Help us understand the problem. What is going on with this article?

Rubyアプリの環境変数設定(ローカル・Heroku)

More than 3 years have passed since last update.

環境変数の持たせ方と呼び出し方に困ったので。

Herokuの場合の持たせ方

addをrmにすれば削除もできるらしい

$ heroku config:add CONSUMER_KEY="hogehogehoge"

ローカルの場合の持たせ方

何かシェルファイルに持たせて
sourceコマンド等で一括適用すればよさそう。

$ export CONSUMER_KEY="hogehogehoge"

呼び出し方

config.consumer_key = ENV['CONSUMER_KEY']

Herokuでまとまった環境変数を読みたい場合

下記のようなデータをファイルに書き込んでおき、ワンライナーで一気に設定する。
ローカル用にexportでもやりたかったのですが、xargsに渡した後だとexportコマンドの参照がうまくいかず。

CONSUMER_KEY="hogehogehoge"
cat set_env.txt | sed -e "s/\n/ /g"  | xargs heroku config:add

参考:設定ファイルの値をまとめて Heroku に設定するコマンド

cjeecsiy
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした