Coder Social home page Coder Social logo

Comments (15)

 avatar commented on July 22, 2024 1

I had a similar issue where my password started with "#", turns out that commented out the password string and I kept on getting "no password supplied"...

from dotenv.

technicalpickles avatar technicalpickles commented on July 22, 2024

Also, I should note that this is Rails 3.2.11, and I was using dotenv successfully in this application previously, but only in config/initializers/*.rb.

from dotenv.

technicalpickles avatar technicalpickles commented on July 22, 2024

Disregard, had 0.4.0 locked, and updating to 0.5.0 fixed 😓

from dotenv.

bkeepers avatar bkeepers commented on July 22, 2024

What version of dotenv are you using? I just pushed a new version last week that loads earlier in the bootstrap process, which should fix this issue.

from dotenv.

bkeepers avatar bkeepers commented on July 22, 2024

haha, posted at the same time :P

Glad it's working!

from dotenv.

AquaGeek avatar AquaGeek commented on July 22, 2024

This doesn't seem to be working with Ruby 2.0.0-p0 and Rails 4.0.0.rc2. Using the same <%= raise ENV.inspect %> trick, none of my variables in my .env file show up.

from dotenv.

aurels avatar aurels commented on July 22, 2024

I have the same problem with dotenv 0.9.0 and rails 3.2.14. Is it supposed to work with these versions ?

Thanks !

from dotenv.

bkeepers avatar bkeepers commented on July 22, 2024

I'm quite certain it works for those versions. Can you post more details on what your .env file looks like and the behavior you're seeing?

from dotenv.

aurels avatar aurels commented on July 22, 2024

Of course :

.env :

RAILS_ENV="staging"

MYSQL_HOST="xxxx" 
MYSQL_DATABASE="dddd"
MYSQL_USERNAME="uuuuu"
MYSQL_PASSWORD="ppppp"

config/database.yml :
<%= ENV['RAILS_ENV'] %>:
adapter: mysql2
host: <%= ENV['MYSQL_HOST'] %>
database: <%= ENV['MYSQL_DATABASE'] %>
username: <%= ENV['MYSQL_USERNAME'] %>
password: <%= ENV['MYSQL_PASSWORD'] %>
encoding: utf8
pool: 200

When doing a bundle exec rails console staging, I get a MySQL error (it cannot connect with default params).

According to the README, as I'm using Rails, I'm not supposed to do that anywhere :

require 'dotenv'
Dotenv.load

Right ?

from dotenv.

aurels avatar aurels commented on July 22, 2024

Note : it fails in staging but not in development. It's probably a mistake on my side.

from dotenv.

aurels avatar aurels commented on July 22, 2024

Nevermind, it works perfectly fine. There was a typo in my .env so the staging connection details where not loaded.

from dotenv.

bkeepers avatar bkeepers commented on July 22, 2024

👍

from dotenv.

rewritten avatar rewritten commented on July 22, 2024

It does not work for me (Rails 2.3.17 app).

The only way to have .env loaded in time for the database, is to add at the end of config/preinitializer.rb:

# ... after Bundler magic

require 'dotenv'

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
Dotenv.load ".env.#{ENV["RAILS_ENV"]}", '.env'

from dotenv.

bkeepers avatar bkeepers commented on July 22, 2024

RAILS_ENV/RACKE_ENV must be specified outside of dotenv. It's a chicken and egg problem that is impossible for dotenv to solve.

from dotenv.

rewritten avatar rewritten commented on July 22, 2024

Even with RAILS_ENV already in env, the Railtie version of dotenv is not loading sooner than the database.yml parsing. The point (sorry for not being clear enough) is, what is the correct step to load the env files in rails 2.3, so database.yml has enough data?

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.