Forum: Ruby on Rails access to database.yaml elements

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
64c2a6af59b9003933906f26b37f4f81?d=identicon&s=25 Al (Guest)
on 2007-03-27 22:11
(Received via mailing list)
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
181035f8aac1cb68d50dc58b67dc0349?d=identicon&s=25 Mischa Berger (mischa78)
on 2007-03-27 22:33
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
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-03-27 22:34
(Received via mailing list)
> 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
This topic is locked and can not be replied to.