How connect to db depending on @request.host value?
How connect to different db depending on @request.host value?
Using Sinatra and MongoDB with Mongoid.I need to read a Sintra application's menu, data ... from different databases. I wish to deploy it only in one place and depending on request.host(subdomain) value to 开发者_如何学Pythonserve the specific pages.
You're probably better off storing all your data in one database marking/tagging/categorizing it depending on the subdomain you're on.
If you setup your Mongoid connection manually already, you could do something like this:
connection = Mongo::Connection.new
Mongoid.database = connection.db(@request.host)
But still, I think you're better of with one database.
精彩评论