ruby - Connect to 2 databases from same model in Rails -


i have application run in 2 different countries. lets , brazil. have user model connects or brazil depending on param passed calling:

user.establish_connection("brazil_db") user.establish_connection("us_db")

the problem facing if user comes in middle of session brazil user activerecord drops brazil connection , connects db.

is there way manage such situations in activerecord?

you should have 1 database nationality flag on relevant tables, or 2 different applications deployed in different datacentres. kind of thing will enormous hassle.

activerecord can handle having different tables in different databases, it's not capable of understanding how handle 1 table living in several @ same time. need extension manage this.

the problem becomes serious when things like:

 model.find(params[:id]) 

which connection should use that? unless have additional context answer "i don't know."

it sounds should deploy 2 instances of application each different database.yml file.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -