RoR 4 - Connection to multiple databases

Hi there,

is it somehow possible to connect from a running Rails4-app to another
database?

My problem is that I have to transfer records from a table from the main
database to a different database.

I just found a solution to connect to a seperate database.

i) You have to put another entry to your database.yml.
Let it be something like this here:

secound_database:
adapter: postgresql
[…]

ii) Create a new model with the same name of your secound database:
secound_database.rb :

class SecoundDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection(‘secound_database’)
end

iii) Create another model, with the name of the table of your secound
database:
some_table.rb:

class SomeTable < SecoundDatabase

end

That’s it guys!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs