Reputation: 885
Hello I am having issues with getting environment variables working. I exported them onto the server doing this:
Export username=name password=password
And when I do Irb and type of the variable I get it back:
2.2.1 :001 > ENV["password"]
=> "password"
However I am getting this error in postgresql:
PG::ConnectionBad: FATAL: password authentication failed for user "ENV["username"]"
It seems my Environmental variables aren't loading into the system. This is my database.yml file:
production:
<<: *default
database: postgresql
username: ENV["username"]
password: ENV["password"]
When I put in the raw string it works perfectly. Any help would be awesome.
Upvotes: 0
Views: 100
Reputation: 84114
Yaml itself knows nothing about environment variables, however rails runs the file through erb before parsing the yaml and that's where you can do things like load environment variables.
You need to use erb tags ( <%= %> ) or else rails will use the literal ENV['password'] as the password, for example:
password: <%= ENV['password'] %>
Upvotes: 5