Gems
ruby 1.9.3
rails 3.2.11
devise 2.2.3
acts_as_tenant 0.2.9
The code
All my models are limited to domain_id:
class User < ActiveRecord::Base
acts_as_tenant(:domain)
end
Then, in my application_controller application, I installed the current tenant from the domain:
class ApplicationController < ActionController::Base
set_current_tenant_through_filter
before_filter :set_tenant
protect_from_forgery
def set_tenant
@domain = Domain.find_or_create_by_name(request.host)
set_current_tenant(@domain)
end
end
Everything works well for all models, with the exception of sessions: Each time a page loads, it will exit the first user who loads the page with another tenant. By downloading this page, he will log out of the first user who [... etc.]
:, , Rails current_tenant = alice_domain (ok). , , , load current_tenant = bob_domain. , Rails current_tenant == bob_domain. Rails : bob_domain, Devise Alice . application_controller current_tenant = alice_domain... .
: act_as_tenant , , . , Devise . , act_as_tenant default_scope . , .
. .