Question

So I am trying to set an environment variable for my rails production environment database as suggested in the .yml file. In my .bash_profile I export it like this:

export DATABASE_URL=mysql2://<username>:<password>@localhost/<database>

I go to my website and i get "ActiveRecord::AdapterNotSpecified" error.

The only thing I can think of is that my password ends in an @ sign which would make the url have @@ and get confused where the password ends and the host begins?

Also this app is hosted on Hostmonster if that helps

database.yml:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: <username>
  password: <password>
  database: <database>

development:
  <<: *default
  database: <database>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: <database>

# Avoid production credentials in the repository,
# instead read the configuration from the environment.
#
# Example:
#   mysql2://myuser:mypass@localhost/somedatabase
#
production:
  url: <%= ENV["DATABASE_URL"] %>
Was it helpful?

Solution

You may need to include the default part as well:

production:
  <<: *default

If your password has an @ in it, try encoding it for a URL:

password%40

That could be the thing. Either that or pick a password that's URL-friendly.

As a note, it's usually best to host the database.yml file for production exclusively on the target server, then symlink it in when you deploy the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top