I use acts_as_tenant gem to manage multi-tenancy, and I use a utility to manage users.
I only have to configure the user model and account model for tenants. I can create users against several tenants - all this works fine EXCEPTION, when I try to create two users with the same email address against different tenant identifiers, I get an uniqeness error. I use the validates_uniqueness_to_tenant parameter as described.
User model
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me acts_as_tenant(:account) validates_uniqueness_to_tenant :email end
Account model
class Account < ActiveRecord::Base attr_accessible :name end
Application controller
class ApplicationController < ActionController::Base set_current_tenant_by_subdomain(:account, :subdomain) protect_from_forgery end
It seems like it should work on the basis of all the documentation in act_as_tenant, is it necessary to redefine something at the development level instead?
EDIT: After some head scratches and a little break, the problem is what I think, because by default Devise added a unique index to the Email column. This is clearly not a gel with what act_as_tenant wants to do ... I will try to remove the index and see if Devise gets confused or not.
EDIT 2: OK, officially abandoned this at the moment. I have manual authentication for the main site and this works correctly with act_as_tenant. I can only assume some incompatibility between act_as_tenant and Devise at some level - outside of me, to find it at this stage.