What started as a minor annoyance now turned into a headache. I am building a Rails 4 application and using Foreman for my dev installation with a Procfile and .env file for configuration. When I set the ENV variable in the .env file, it is correctly selected by my application. In this case, I set some ENV options for Paperclip in the initializer.
The problem arises when I go to change the value of ENV variables. In the console, if I type ENV ["MY_VAR"], it shows the new value. However, the value that was used in my initializer, which was supposedly launched when the console started, shows the old value! Nowhere in my project is the old value indicated anywhere. This makes me think that the environment is somehow cached or that the env variables are exported to my shell. I'm running out of places to watch, so any help would be greatly appreciated! I am developing on Mac (10.9.4) with Ruby 1.9.3-p374 and Rails 4.1.0.
Example:
ROOT / .env
S3_BUCKET=mybucket
configurations / Initializers / paperclip.rb
Paperclip::Attachment.default_options[:s3_credentials] = {bucket: ENV["S3_BUCKET"]}
If I changed the value of S3_BUCKET to "newbucket" and ran "runman rails c" or "rails c" to enter the console, this is what happens:
ENV["S3_BUCKET"] # => "newbucket" Paperclip::Attachment.default_options[:s3_credentials] # => {bucket: 'mybucket'}
I should mention that this behavior also occurs in my classes that I injected into / lib. I think it's all because of something stupid that I forgot. Any ideas?
ruby-on-rails environment-variables development-environment foreman
Spencer
source share