Access to database.yaml elements


#1

I’d like to be able to display which db is the active db as
I have a couple of development databases that I switch between,
and I’d like the interface to remind me which one I’m dealing with by
displaying some of.

Can someone point me somewhere where I can have it show me the name of
the database that’s being accessed?

Thanks,

-Al


#2

You could do it like this:

require ‘yaml’
config = YAML.load(File.open(‘config/database.yml’))
config[‘development’][‘database’]

Cheers,

Mischa


http://boxroom.rubyforge.org


#3

I’d like to be able to display which db is the active db as
I have a couple of development databases that I switch between,
and I’d like the interface to remind me which one I’m dealing with by
displaying some of.

Can someone point me somewhere where I can have it show me the name of
the database that’s being accessed?

I can’t, but here’s the code we use to read our ‘site.yml’ file (for
local
config stuff) that follows the exact same format as database.yml…

SITE_YAML = YAML::load(ERB.new(IO.read("#{RAILS_ROOT}/config/site.yml"),
nil, ‘-’).result)
SITE_YAML_ENV = SITE_YAML[RAILS_ENV]

So assuming you switched that over to database.yml then you could spit
out

SITE_YAML_ENV[‘database’]

and you’d have your current database…

-philip