开发者

How connect to db depending on @request.host value?

开发者 https://www.devze.com 2023-01-23 00:28 出处:网络
Howconnect to different db depending on @request.hostvalue? Using Sinatra and MongoDB with Mongoid. I need to read a Sintra application\'s menu, data ... from different databases. I wish to deploy it

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消