Creating environment variables with Rails 6 and Heroku

Viewed 1282

How do I create a group of environment variables that can be used both locally in development and on Heroku using Rails 6?

1 Answers

There are many different ways to configure environment variables, and people have many different preferences.

Personally, for my local development, I typically use the dotenv gem. I'll git-ignore .env, but I'll add a .env.example with all the vars I need stubbed out.

Then in my local checkout(s), I'll cp .env.example .env, and I will edit that .env file for all of my local configuration.

dotenv-rails includes a railtie to load environment variables from the .env file if they have not already been supplied as real env vars.

When I deploy to Heroku, I just use the Heroku console or GUI to set up my environment variables there.

Related