[英]ActiveRecord one connection per request
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. 根据用户选择的环境选择,activerecord将使用数据库X或Y。
But when I use ActiveRecord::Base.establish_connection, activerecord change the database for all users. 但是,当我使用ActiveRecord :: Base。Establishment_connection时,activerecord会更改所有用户的数据库。 I want that user 'A' use Database 'X' and user 'B' use Database 'Y' at the same time in one single application. 我希望用户“ A”在一个应用程序中同时使用数据库“ X”和用户“ B”同时使用数据库“ Y”。 Is that possible with rails? 铁轨有可能吗?
I am thinking that you can do something like this 我在想你可以做这样的事情
you do need to declare the connection in your /config/database.rb 您确实需要在/config/database.rb中声明连接
MyModel < ActiveRecord::Base
establish_connection "other_#{session[:user_db]}"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.