Read database.yml - How To

This is useful if you want to have a hash that contains values of your ‘development’ or ‘production’ configuration.

If it is after the Rails app started, we can just do:

config = Rails::Configuration.new
database = config.database_configuration[”production”]
(Now you have access to database[:password], etc)

Without Rails, we can do

file_handle = YAML.load(File.new(”path/to/database.yml”)
hashes = file_handle.each {|value| value.inspect}
(Now you have access to hashes[”production”])

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.