views:

53

answers:

3

Hi Everyone,

Are there any ways to retrieve the database connection string where my ruby is connected? what i would like to get is the:

1) Database name where the ruby is connected 2) The username of the SQL Server 3) Password of the SQL Server 4) Server name

I want to store it in session variables.

(I'am using MS SQL Server.)

Please help! thanks!

A: 

These values are all stored in the file config/database.yml, but AFAIK you can't access these values as variables from within your controller.

nfm
Your app could read/interpret the config/database.yml file. It'd then have all of the info to do with as it wished.
Larry K
A: 

Database: ActiveRecord::Base.connection.current_database

You could also do some fancy Regexs with the following:

ActiveRecord::Base.connection.inspect

But yeah, this is a terrible idea.

Patrick Klingemann
using ActiveRecord::Base.connection.inspect does show the username and password but i' am having problems in regexs, i cannot get just let say the password only
Jett
+1  A: 

You can access all of the properties described in your database.yaml like this:

ActiveRecord::Base.configurations["development"] => 
{"encoding"=>"utf8", "username"=>"foo", "adapter"=>"mysql", "database"=>"bar_development", "host"=>"localhost", "password"=> "baz"} 
Tanel Suurhans