Refresh ENV during runtime
albertski opened this issue · comments
Albert Jankowski commented
I created a console command that updates my .env file, but also in the same runtime, it accesses ENV. The problem is that it reads the old values, even though I updated the .env file. Is there a way to refresh the ENV during runtime so it gets the latest values?
I tried Dotenv.load('.env')
but it didn't help.
.env
FOOBAR=hello
ruby.rb
puts ENV['FOOBAR'] # Prints "hello"
EnvFile.update_variable('.env', 'FOOBAR', "How are you?")
Dotenv.load('.env')
puts ENV['FOOBAR'] # Prints "hello" even though looking in .env it has the new value "How are you?"
Dominik Čermák commented
Use Dotenv.overload('.env')
Albert Jankowski commented
Thanks for your help. That worked perfectly.