Priti Priti - 5 months ago 17x
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?


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.