0

I have an application that let the user to connect in multiples environments. Depending of the choice of environment that the user pick, activerecord will use Database X or Y.

But when I use ActiveRecord::Base.establish_connection, activerecord change the database for all users. I want that user 'A' use Database 'X' and user 'B' use Database 'Y' at the same time in one single application. Is that possible with rails?

2 Answers2

0

I am thinking that you can do something like this

you do need to declare the connection in your /config/database.rb

MyModel < ActiveRecord::Base
    establish_connection "other_#{session[:user_db]}"
end
Thor odinson
  • 180
  • 1
  • 11
0

You can try this answer.

Based on user type (X or Y), you can establish the respective DB connection.

Or,

You can try this gem.

Community
  • 1
  • 1
Jayaprakash
  • 1,407
  • 1
  • 9
  • 19