Test a new database connection from ruby on rails console

Sometimes we want to test a new database connection from rails console mainly to see if firewall is blocking it or not.

Test: ActiveRecord::Base.establish_connection

Run the following with correct details on rails console

ActiveRecord::Base.establish_connection(
{ :adapter => ‘postgresql’,
:database => ‘database_name’,
:host => ‘x.x.x.x’,
:username => ‘username’,
:password => “username” }
)

Try to access any rails model and create some test records.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store