अपने एप्लिकेशन नियंत्रक में ऐसा कुछ डालें। मैं डेटाबेस का नाम चुनने के लिए सबडोमेन प्लस "_clientdb" का उपयोग कर रहा हूं। मेरे पास एक ही उपयोगकर्ता नाम और पासवर्ड का उपयोग कर सभी डेटाबेस हैं, इसलिए मैं इसे डीबी कॉन्फ़िगरेशन फ़ाइल से पकड़ सकता हूं।
आशा है कि इससे मदद मिलती है!
class ApplicationController < ActionController::Base
before_filter :hijack_db
def hijack_db
db_name = request.subdomains.first + "_clientdb"
# lets manually connect to the 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
स्रोत
2008-09-12 14:01:09