I'm using Rails with Postgres DB Docker container attached. It looks like I'm getting below error when I run rails c
:
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/generic.rb:204:in `initialize': the scheme postgres does not accept registry part: postgres:@ (or bad hostname?) (URI::InvalidURIError)
Is there a reason why this isn't working?
My database.yml
is:
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
$DATABASE_URL
is defined
Interestingly it was working for a few days until yesterday and stopped working again today.
Below is what Rails 4.2.1 generates!
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
Why on earth would they recommend env variable that is reserved!?
UPDATE: Actually this is still not fixed. It looks like environment variable is not being picked up from
database.yml
file when runningrails runner
which is run by cron task to invoke Sidekiq worker job (using Whenever). I had to puturl:
static value instead to get it working for now but given thatdocker
ip changes every time its run from the image I would preferrails runner
to pick up environment variables properly. This may be related to https://github.com/rails/rails/issues/19256#issuecomment-102980786 but the solution didn't work either.