Coder Social home page Coder Social logo

Comments (6)

willglynn avatar willglynn commented on August 24, 2024 3

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.

bkeepers avatar bkeepers commented on August 24, 2024

Environment variables are currently loaded as part of the initialization process. This could probably be done when the gem is loaded.

from dotenv.

fesplugas avatar fesplugas commented on August 24, 2024

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.

bkeepers avatar bkeepers commented on August 24, 2024

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.

weppos avatar weppos commented on August 24, 2024

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.

weppos avatar weppos commented on August 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.