22 lines
647 B
Ruby
22 lines
647 B
Ruby
module MultiTenancy
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
|
|
before_action :set_current_tenant_by_subdomain_or_frist if respond_to? :before_action
|
|
helper_method :current_shop if respond_to? :helper_method
|
|
end
|
|
|
|
private
|
|
def set_current_tenant_by_subdomain_or_frist
|
|
if request.subdomains.last && request.subdomains.last != 'www'
|
|
set_current_tenant(Shop.find_by(subdomain: request.subdomains.last))
|
|
end
|
|
set_current_tenant(Shop.first) if current_tenant.nil?
|
|
end
|
|
|
|
def current_shop
|
|
ActsAsTenant.current_tenant
|
|
end
|
|
end
|