Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add MultiTenantController minus tests.

  • Loading branch information...
commit 36b1a222958845d1e962436ad4a1019f6525bf30 1 parent 91f5a60
@mconnell authored
Showing with 29 additions and 0 deletions.
  1. +1 −0  init.rb
  2. +28 −0 lib/multi_tenant_controller.rb
View
1  init.rb
@@ -1 +1,2 @@
+ActionController::Base.extend MultiTenantController
ActiveRecord::Base.extend MultiTenantModel
View
28 lib/multi_tenant_controller.rb
@@ -0,0 +1,28 @@
+module MultiTenantController
+ def subdomain_by_multi_tenant_model(tenant = :account)
+ self.class_eval do
+ before_filter :find_account_from_subdomain
+ def session
+ if @current_subdomain.present?
+ request.session[@current_subdomain] ||= {}
+ else
+ request.session
+ end
+ end
+
+ def session=(*args)
+ if @current_subdomain.present?
+ request.session[@current_subdomain] = args
+ else
+ request.session = args
+ end
+ end
+
+ private
+ def find_account_from_subdomain
+ @current_subdomain = request.host.split(/\./).first
+ Account.current = Account.find_by_subdomain!(@current_subdomain)
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.