Rails doesn't see environment variable

agustaf picture agustaf · Apr 8, 2016 · Viewed 12.6k times · Source

I am trying to move a Rails application into production but I am having a problem with Rails not seeing my environment variable.

I have the password for my database setup in my .bashrc file like

export APP_NAME_DATABASE_PASSWORD=secretkey

In irb

ENV["APP_NAME_DATABASE_PASSWORD"]

returns secretkey.

Using

RAILS_ENV=production rails c

and just

rails c

returns secretkey but when starting the application I get

Access is denied (using password: NO)

I am using a slightly modified version of the init script on "How To Deploy a Rails App with Unicorn and Nginx on Ubuntu 14.04" to start unicorn.

It is being hosted on Ubuntu Server 14.04.

Answer

Raghav Jajodia picture Raghav Jajodia · May 8, 2019

Try doing spring stop followed by rails c

Spring is a rails application preloader that loads the ENV configuration. It might not have loaded the .bashrc changes in your case.