What is the best way to do per-user database connections in Rails -


what best way per-user database connections in rails?

i realize poor rails design practice, we're gradually replacing existing web application uses 1 database per user. complete redesign/rewrite not feasible.

put in application controller. i'm using subdomain plus "_clientdb" pick name of database. have databases using same username , password, can grab db config file.

hope helps!

class applicationcontroller < actioncontroller::base    before_filter :hijack_db    def hijack_db     db_name = request.subdomains.first + "_clientdb"      # lets manually connect proper db     activerecord::base.establish_connection(       :adapter  => activerecord::base.configurations[env["rails_env"]]['adapter'],       :host     => activerecord::base.configurations[env["rails_env"]]['host'],       :username => activerecord::base.configurations[env["rails_env"]]['username'],       :password => activerecord::base.configurations[env["rails_env"]]['password'],       :database => db_name     )   end end 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -