Why are my gem 'dotenv-rails' variables not loading?

Viewed 7049
  • gem 'dotenv-rails' is required in gemfile test and development environments.
  • .env file is saved in root
  • I believe variables use correct syntax; USERNAME=username
  • I am using Rails 5.0.4
  • I have not required 'dotenv-rails' anywhere, as the docs do not suggest that I need to.

When playing in the console, the only way I can access the variables is by calling, Dotenv.load in each session. Suggesting that Dotenv.load should be called somewhere in config of my app.

3 Answers

In case this helps anyone else:

This happened to me once. As it turns out, I was mistakenly passing RAILS_ENV=production in the environment variables, disabling it.

You may also need to restart Spring.

bin/spring stop

It will restart once you run another rails command.

Related