Reputation: 14029
There are times where I'd like my Heroku console to do something differently but only for that instance. While I'm able to control this through command line arguments it can get a little long/messy.
I'm trying to pass temporary ENV vars to Heroku when booting a console but am so far unable to. I'd like to run SOME_VAR=some_value heroku run console --app myapp
but once Rails boots, I do not have ENV['SOME_VAR']
.
I know I can set this and then delete it from the Heroku website but that restarts the server which I'd like to avoid.
Is there a way to pass temporary ENV
vars to Rails apps running on Heroku without setting them in the Heroku dashboard?
Upvotes: 5
Views: 1766
Reputation: 4930
Lately I've been unable to pass in variables as strings that include spaces. What worked is the following:
heroku run rails c -a my-app -e "ONE=my first var;TWO=another one"
The -e
flag is lightly documented in the docs.
Upvotes: 6
Reputation: 24337
You must set the variable AFTER heroku run
:
heroku run MYVAR=hello rails console
Once you're connected, you can verify that MYVAR is set:
puts ENV['MYVAR']
=> "hello"
Upvotes: 19