Comments (6)
Alternately, to load environment variables immediately, we could specify something like:
gem 'dotenv', :require => 'dotenv/load'
This behavior could also be useful outside of a Rails context.
from dotenv.
Environment variables are currently loaded as part of the initialization process. This could probably be done when the gem is loaded.
from dotenv.
Maybe would be interesting to explain on the documentation in which parts of the application you cannot use ENV vars when using dotenv
. As far as I know:
- config/application.rb
- config/environments/*
from dotenv.
I just pushed ed610ea, which uses the #before_configuration
, which makes it work in config/environments/*
. config.application.rb
still needs more investigation.
from dotenv.
I run into the same issue today, trying to make the ENV['MEMCACHE_SERVERS']
variable available to the cache_store
.
config.cache_store = :dalli_store
ed610ea doesn't solve the issue because the config
calls are evaluated before before_configuration
is executed (reference).
I solved it manually loading it in my application.rb
file immediately after Bundler
setup.
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
Dotenv.load ".env.#{Rails.env}", '.env'
module MyApp
class Application < Rails::Application
However, in this case the .env
is loaded twice because the before_configuration
still exists. It would be great if the library understands where a #load
call has already been execute and skip subsequent calls unless forced.
from dotenv.
@willglynn If you load it at bundler level, I'm not sure you will be able to access Rails.env
from dotenv.
Related Issues (20)
- Could not find dotenv-2.7.6 in any of the sources HOT 1
- Just HOT 1
- Special characters are being escaped from the value of the environment variables HOT 3
- dotenv-rails loads dev environment when running system tests with Rails 7 HOT 5
- `Dotenv.load` call causes Rails app to be loaded twice HOT 2
- Not specifying required ruby version on Gemfile causes my bundler with ruby 2.5.x pull dotenv 2.8.0 HOT 6
- template is not created in working directory HOT 2
- Question on Removal of ### What other .env* files can I use? FAQ HOT 1
- README should explicitly call out the gem needed is `dotenv-rails` HOT 4
- environment specific env not loaded when using require: 'dotenv/load' HOT 1
- Rails < v6.1: LocalJumpError in tagged logging HOT 2
- autorestore: can't modify frozen Hash HOT 7
- Use existing TaggedLogger instead of re-wrapping it with `TaggedLogging` HOT 4
- Ruby warning: circular require considered harmful HOT 2
- v3.0.3 causes regression with semantic-logger v4.15.0 HOT 2
- [BUG] All logs are tagged with "dotenv" HOT 1
- Dotenv's tagged method conflicts with SemanticLogger's HOT 1
- loading multiple files are not correctly overwriting env variables HOT 1
- ActiveSupport::TestCase teardown error: undefined method `keys' for nil HOT 3
- Use ERB in env file? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotenv.