Hello all. Due to the mistakes of the company before I joined ;) I am stuck with a multiple database setup. I am planning on parsing the REQUEST_URL to decide which controller is being accessed and basing the establish_connection on that. Before I go messing around with regexps I was wondering if rails has a built in function for parsing URLS. I have googled around a bit and seen net/http but I cannot find an API for it. Thanks Jeff -- Posted via http://www.ruby-forum.com/.
Jeff Jones wrote:> Hello all. > > Due to the mistakes of the company before I joined ;) I am stuck with a > multiple database setup. I am planning on parsing the REQUEST_URL to > decide which controller is being accessed and basing the > establish_connection on that. Before I go messing around with regexps I > was wondering if rails has a built in function for parsing URLS. I have > googled around a bit and seen net/http but I cannot find an API for it.The request URL is chopped up by config/routes.rb. I''d start there. -- Alex
Alex Young wrote:> Jeff Jones wrote: >> Hello all. >> >> Due to the mistakes of the company before I joined ;) I am stuck with a >> multiple database setup. I am planning on parsing the REQUEST_URL to >> decide which controller is being accessed and basing the >> establish_connection on that. Before I go messing around with regexps I >> was wondering if rails has a built in function for parsing URLS. I have >> googled around a bit and seen net/http but I cannot find an API for it. > > The request URL is chopped up by config/routes.rb. I''d start there.I found out about require ''URI'' and ended up using that. class ApplicationController < ActionController::Base before_filter :change_database def change_database path = URI.parse(request.env["REQUEST_URI"]).path comp = path.split(''/'') if comp[1].downcase == ''sheet'' ActiveRecord::Base.establish_connection( :adapter => "XXX", :database => "XXX", :host => "XXX", :username => "XXX", :password => "XXX" ) elsif comp[1].downcase == ''component'' ActiveRecord::Base.establish_connection( :adapter => "XXX", :database => "XXX", :host => "XXX", :username => "XXX", :password => "XXX" ) end end end Cheers Jeff -- Posted via http://www.ruby-forum.com/.
Jeff Jones wrote:> Alex Young wrote: >> Jeff Jones wrote: >>> Hello all. >>> >>> Due to the mistakes of the company before I joined ;) I am stuck with a >>> multiple database setup. I am planning on parsing the REQUEST_URL to >>> decide which controller is being accessed and basing the >>> establish_connection on that. Before I go messing around with regexps Ithere are easier ways to determine the controller... params[:controller] in a before_filter should do the trick... -- Posted via http://www.ruby-forum.com/.
Mikkel Bruun wrote:> there are easier ways to determine the controller... > > params[:controller] in a before_filter should do the trick...heh, try self.class in a before filter in ApplicationController, its probably the best way... -- Posted via http://www.ruby-forum.com/.