mysql - Multiple concurrent database connections in rails -


i have rails application used several customers. each client access trough domain, domains work same rails app:

my-client-1.mycompany.com my-client-2.mycompany.com my-client-n.mycompany.com 

the application works multiple databases, 1 database per client. of databases have same structure, identical. have 1 configuration per database in database.yml:

my-client-1:  adapter:  username:  my-client-2:  adapter:  username:  ... 

i need indicate app based on domain used 1 user, must change database corresponding. example if user enters through my-client-2.mycompany.com database use must my-client2.

i have done including in application_controller.rb code:

before_filter :set_db_connection    def set_db_connection      d = request.host.split('.')      current_domain = d[0]      activerecord::base.establish_connection current_domain   end 

now have next 2 questions:

  1. ¿is right way solve problem?
  2. ¿what happens if 1 user processing , takes 60 seconds, , in moment user enters through other domain , change connection because of code above. affect first user buy changing connection , @ point process takes 60 secs read or write wrong database?

thanks


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -