Technical
Reading Database Yml Pragmatically

How to read config info From Database.yml

Originally found @ Panasonic Youth
and will remove if asked. But I do want to thank the author very much.

I had a place in my app where I needed to update audit logs that were generated by triggers ( was not mine idea ) with the user name thats currently loged in. The user name would obviously change in different environments [test,development,production] which were making it very hard for me to test, so I decided to read config file for username and test based on that.

So thats how you read database.yml without reading it by useing YAML methods but just through rails.


config = Rails::Configuration.new>> config.database_configuration["production"] 
#=> {"dbfile"=>"db/m001_reloaded_production.sqlite", "adapter"=>"sqlite3"}