Forum: Ruby on Rails Getting database config info

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
005df2b73028b2e39304ac59768d709f?d=identicon&s=25 Robbie Carlton (Guest)
on 2006-02-01 15:56
(Received via mailing list)
Hi folks. I have a very small problem which is probably very simple. But
I've scoured the api and the rails book with no luck.
I'm trying to get information about the database definition out of
record. When I go into console and say


I get a MysqlAdapter object, with an instance variable called @config
a hash containing all the information I need. However I can't get at the
config variable. I can think of two solutions, neither of which is
satisfactory. Either extend the definition of MysqlAdapter to include an
accessor for database name, but I'm loathe to do this as it's hacky and
cause problems with switching to different database types and updates to
rails. The other is to parse the config file myself, but again this is
clearly not clever as it's duplication.

Thanks in advance

F16def8015a7562a285c65a14be48540?d=identicon&s=25 Mathieu Chappuis (Guest)
on 2006-02-01 16:11
(Received via mailing list)
I've asked a similar question, Peter has helped me as follow.

Hope this help you too

From: Peter Donald <>	Mailed-By:
Date: Dec 22, 2005 10:50 PM
Subject: Re: [Rails] [NEWB] How to access database.yml parameters in a

On 12/23/05, Mathieu Chappuis <> wrote:
> Are the active database.yaml attributes for the current environment
> (dev, prod, test) available inside a controler ?

005df2b73028b2e39304ac59768d709f?d=identicon&s=25 Robbie Carlton (Guest)
on 2006-02-01 16:23
(Received via mailing list)
thank you very much. I couldn't get this to work in console


I didn't try it in a controller, but following your lead I did get this
work, which does exactly what I need


41165a7e7126d616a0ae0762e00718e2?d=identicon&s=25 BigSmoke (Guest)
on 2006-02-02 20:47
(Received via mailing list)
I had some trouble finding these answers, because I couldn't find out
a decent set of keywords to search for. After finding the answer in
this thread, I added it to [1]. If you will, please take a look and
modify it in any way you see fit.

Thanks for providing the answer to my question,

  - Rowan

This topic is locked and can not be replied to.