Single database for multiple shops
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
This commit is contained in:
20
app/controllers/concerns/multi_tenancy.rb
Normal file
20
app/controllers/concerns/multi_tenancy.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
Reference in New Issue
Block a user