Created
May 11, 2017 03:14
-
-
Save deep-spaced/5a8d86cf144ac916aab074536a8690d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdminController < ApplicationController | |
set_current_tenant_through_filter | |
before_action :authenticate_user! | |
before_filter :load_tenant | |
def load_tenant | |
begin | |
tenant = if session[:current_tenant] | |
# Retrieve the tenant | |
Tenant.find(session[:current_tenant]) | |
elsif current_user.tenants.size > 0 | |
current_user.tenants.first | |
else | |
nil | |
end | |
if tenant | |
set_tenant(tenant) | |
else | |
end | |
rescue | |
session[:current_tenant] = nil | |
redirect_to destroy_user_session_url | |
end | |
end | |
def set_tenant(tenant) | |
set_current_tenant(tenant) | |
session[:current_tenant] = tenant.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment