views:

29

answers:

1

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 serve the specific pages.

A: 

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.

Ariejan