Module: MultiTenantSubdomain
- Defined in:
- lib/multi_tenant_subdomain.rb,
lib/multi_tenant_subdomain/railtie.rb,
lib/multi_tenant_subdomain/version.rb,
lib/multi_tenant_subdomain/middleware.rb,
lib/multi_tenant_subdomain/tenant_manager.rb,
lib/multi_tenant_subdomain/active_record_extension.rb,
lib/generators/multi_tenant_subdomain/multi_tenant_subdomain_generator.rb
Overview
This module provides multi-tenant subdomain functionality for Rails applications.
It allows you to easily scope your application’s data and functionality to different tenants based on the subdomain in the request URL.
To use this module, you need to:
1. Generate the necessary migrations and configurations using the provided generator:
`rails generate multi_tenant_subdomain YourTenantModelName`
2. Configure the module with your tenant model class and primary/foreign keys:
```ruby
MultiTenantSubdomain.configure do |config|
config.tenant_model_class = "Account" # Default: "Tenant"
config.tenant_model_table = "accounts" # Default: "tenants"
config.tenant_model_pk = "id" # Default: "id"
config.tenant_model_fk = "account_id" # Default: "tenant_id"
end
```
3. Use the `MultiTenantSubdomain::TenantManager.current_tenant` method to access the
current tenant in your controllers and views.
Defined Under Namespace
Modules: ActiveRecordExtension Classes: Configuration, Error, Middleware, MultiTenantSubdomainGenerator, Railtie, TenantManager
Constant Summary collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
-
.config ⇒ Configuration
The configuration object for the module.
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Object
Configures the module.
Class Attribute Details
.config ⇒ Configuration
Returns The configuration object for the module.
76 77 78 |
# File 'lib/multi_tenant_subdomain.rb', line 76 def config @config end |
Class Method Details
.configure {|config| ... } ⇒ Object
Configures the module.
90 91 92 93 |
# File 'lib/multi_tenant_subdomain.rb', line 90 def configure self.config ||= Configuration.new yield(config) if block_given? end |