Skip to content

Instantly share code, notes, and snippets.

@deep-spaced
Created May 11, 2017 03:14
Show Gist options
  • Save deep-spaced/5a8d86cf144ac916aab074536a8690d7 to your computer and use it in GitHub Desktop.
Save deep-spaced/5a8d86cf144ac916aab074536a8690d7 to your computer and use it in GitHub Desktop.
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