In Rails Connect to Remote Database on localhost, task can be achieved by editing database.yml file in your Rails application. Make changes to host, username, password and database in your database yaml file to connect to remote database.
Read this post on rubyinrails.com