Ruby on rails - how to restore connection strings

Is there a way to get the database connection string where my ruby ​​is connected? I would like to get:

1) Name of the database in which the ruby ​​is connected 2) SQL Server username 3) SQL Server password 4) Server name

I want to save it in session variables.

(I am using MS SQL Server.)

Please, help! thank!

+5
source share
5 answers

You can access all the properties described in your database.yaml file:

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

I would go with ActiveRecord::Base.connection_config, which returns a hash with parameters for ActiveRecord 3.

+5
source

config/database.yml, AFAIK .

0

: ActiveRecord::Base.connection.current_database

You can also make some fancy regular expressions with the following:

ActiveRecord::Base.connection.inspect

But yes, this is a terrible idea.

0
source

It looks like you just want to connect directly to the database. You can do this with rails dbconsole(see docs )

0
source

All Articles