Since Rails 4.2, without additional gems, you can load config/hi.yml simply by using Rails.application.config_for :hi
.
For example:
touch config/passwords.yml
#config/passwords.yml
development:
username: 'a'
password: 'b'
production:
username: 'aa'
password: 'bb'
touch config/initializers/constants.rb
#config/initializers/constants.rb
AUTHENTICATION = Rails.application.config_for :passwords
and now you can use AUTHENTICATION
constant everywhere in your application:
#rails c production
:001> AUTHENTICATION['username'] => 'aa'
then add passwords.yml to .gitignore: echo /config/passwords.yml >> .gitignore
, create an example file for your comfort cp /config/passwords.yml /config/passwords.example.yml
and then just edit your example file in your production console with actual production values.