Jack
Jack

Reputation: 5434

Rails gem not using environment variable

I have created a Rails gem and a Rails app that uses that gem. The gem is deployed at Gemfury, and I successfully am able to bundle install the gem. In the gem, I have a variable set to an environment variable. When I run my app locally, the places in the app that use environment variables are able to read my environment variables (managed by Figaro), but the gem is not able to. What might I be missing or doing wrong?

For example if I do this in the gem:

 cache_enabled = ENV['CACHE_ENABLED'] || false

It will end up as false even if my environment variable CACHE_ENABLED = true. My Rails app reads environment variables with no problem.

I'm using Rails 4 if that makes a difference.

Upvotes: 1

Views: 1189

Answers (1)

davetapley
davetapley

Reputation: 18010

If you are using Rails 4.1 or above then it's probably Spring.

You should be able to $ spring stop, then run your app correctly (as spring will restart with the new env vars).

You can remove spring permanently per this.


As a side note, I tend to use Foreman locally (including the lesser known foreman run) command, if you do that then you can prepend DISABLE_SPRING=1 to your .envs and Spring will be bypassed whenever you use Foreman.

Upvotes: 1

Related Questions