1

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.

5
  • So, the environment variables are set locally, yes? Where is the production app located? Commented Dec 13, 2013 at 1:08
  • Can you verify that the environment you're setting the variable in is the same that you're running the library in? Commented Dec 13, 2013 at 1:10
  • @Mallanaga I'm setting the environment variables locally and running locally. When I go to production, I'll put it up in Heroku and set the Heroku environment variables. Commented Dec 13, 2013 at 1:23
  • @zeantsoi If I'm running the Rails app that specifies gems in its Gemfile, those gems are running in the same environment as the app right? Commented Dec 13, 2013 at 1:39
  • please add debug lines: p ENV['CACHE_ENABLED'].class, and p cache_enabled after the codeline. and show us a result. Commented Dec 13, 2013 at 11:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.