9

I am trying to debug a problem with secrets.yml loading environment variables, by setting some environment variables in development and running rails c to inspect things. When I load Rails.applications.secrets this way, it is not picking up any of the environment variables I have set (namely, SECRET_KEY_BASE)

If I run the application with the same environment variables set, it picks them up fine (I'm using RubyMine to run the application, but running rails c from the terminal)

In my rails console, I can see the environment variable I've set using ENV['SECRET_KEY_BASE'], but it doesn't show up in Rails.application.secrets. Why?

mltsy
  • 6,598
  • 3
  • 38
  • 51

1 Answers1

32

TL;DR: spring stop

It turns out, as has happened so many times when things aren't making any sense, Spring is the culprit! I solved this problem (thanks to a related discussion) by running spring stop and then trying again, after which it worked perfectly!

Apparently Spring was caching the environment, or certain pieces of the Rails application, and neglecting to reload them when the environment variables changed.

mltsy
  • 6,598
  • 3
  • 38
  • 51