I created an application.yml
file in the config dir and added some key-value pairs (i.e. AWS_REGION: us-east-1
). I also added the following to application.rb
to read the file and update the ENV hash:
if Rails.env.development?
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'application.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
end
end
Then, if I run rails c
I can see the ENV variables I set in my application.yml
file (i.e. ENV['AWS_REGION']
). However, if I update any of the values or even add a new key-value pair to the file, on the next time I run rails c
the values aren't updated and the new keys aren't available.
I tried restarting Terminal but it didn't work. Any suggestions?