Q:

How to use secrets.yml in ruby on rails 4 to store a password in database.yml

I have a ruby on rails 4 project and my config/secrets.yml looks like this:
development:
  secret_key_base: verylongnumber
  postgres: 'mypassword'

My config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5
  host: localhost
  username: myusername
  password: 'mypassword' # <-- Problem here

What do I need to type in password in my config/database.yml, to get the password from secrets.yml? 
I tried:
password: <%= ENV['postgres'] %>
password: <%= ENV["postgres"] %>
password: <%= ENV[postgres] %>
password: ENV['postgres']
password: ENV["postgres"]
password: ENV[postgres]

But neither of these solutions worked.  Where did I go wrong?  Thanks in advance! 

A:

You need to use <%= Rails.application.secrets[:your_key] %> to access the value of secrets.yml.  
The below should work
<%= Rails.application.secrets[:postgres] %>
I strongly recommend you to have a look at this blog
https://launchschool.com/blog/managing-environment-configuration-variables-in-rails

