Use ActsAsTenant as Multi-tenancy for shops See below files: - app/controllers/concern/multi_tenancy.rb - app/models/application_record.rb - app/models/shop.rb An initializer can be created to control option in ActsAsTenant. config/initializers/acts_as_tenant.rb require 'acts_as_tenant/sidekiq' ActsAsTenant.configure do |config| config.require_tenant = false # true end more details: https://github.com/ErwinM/acts_as_tenant
21 lines
571 B
Ruby
21 lines
571 B
Ruby
module MultiTenancy
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
|
|
before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action
|
|
helper_method :current_shop if respond_to? :helper_method
|
|
end
|
|
|
|
private
|
|
def find_shop_by_subdomain_or_frist
|
|
if request.subdomain.present?
|
|
shop_code = request.subdomain.partition('-').last
|
|
shop = Shop.find_by(shop_code: shop_code)
|
|
else
|
|
shop = Shop.first
|
|
end
|
|
set_current_tenant(shop)
|
|
end
|
|
end
|