Priti Priti - 2 years ago 123
Ruby Question

Multi Tenant gem for mongomapper

I want to create SAAS application in Ruby on rails. So, that every account have different database. I have found apartment gem but it is not working with mongomapper. Is there any multi tenant gem that works with mongomapper?
I have also tried with following code in the model:

class User
include MongoMapper::Document
include ActionView::Helpers
connection('localhost', 27017))
set_database_name "#{current_user.username}"
key :name, String
key :email, String, :required => true
key :username, String, :required => true, :unique => true

but I am not getting username here. I am getting this error "undefined method `connection' for #" when I use database connection code in my controller. What is the best approach to this?

Answer Source

You can use MongoMapper.database = "my_db" from your controller. It will create new my_db database or if its already created then switch to that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download