Last active
October 3, 2018 01:36
-
-
Save dpickett/240a3c473c8d0f95e730f58533b75762 to your computer and use it in GitHub Desktop.
Multitenant
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
module MultitenantBehaviors | |
protected | |
def current_company | |
if request.subdomain && request.subdomain != 'www' | |
# assumes a `subdomain` string field on the Company class / table | |
@current_company ||= Company.find_by(subdomain: request.subdomain) | |
else | |
nil | |
end | |
end | |
end |
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 WidgetsController < ApplicationController | |
include MultitenantBehaviors | |
def index | |
if current_company | |
#assumes an association between Company objects and Widget objects | |
@widgets = current_company.widgets | |
else | |
@widgets = Widget.all | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment