Skip to content

Commit 7e10455

Browse files
authored
Merge pull request #311 from basecamp/flavorjones-extracted-resolver
Update to AR::Tenanted with the extracted tenant resolver
2 parents 113dd3c + 2e70e0c commit 7e10455

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ git_source(:bc) { |repo| "https://github.com/basecamp/#{repo}" }
33
ruby file: ".ruby-version"
44

55
gem "rails", github: "rails/rails", branch: "main"
6-
gem "active_record-tenanted", bc: "active_record-tenanted", branch: "fizzy-temporary"
6+
gem "active_record-tenanted", bc: "active_record-tenanted", branch: "fizzy-temporary-2"
77

88
# Assets & front end
99
gem "importmap-rails"

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GIT
22
remote: https://github.com/basecamp/active_record-tenanted
3-
revision: 8728b0ea622dfbc15dc27f9ec9086a12ef873430
4-
branch: fizzy-temporary
3+
revision: dcb9ee57eebfa85ed5a521c40266a0caaecc4a58
4+
branch: fizzy-temporary-2
55
specs:
66
active_record-tenanted (0.1.0)
77
activerecord (>= 8.1.alpha)

config/initializers/tenanting.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
Rails.application.configure do |config|
2-
# uuugh this resolver proc is so gross.
3-
config.middleware.use ActiveRecord::Tenanted::TenantSelector, "ApplicationRecord", ->(request) { request.subdomain.split(".").first }
1+
Rails.application.config.after_initialize do
2+
Rails.application.config.active_record_tenanted.tenant_resolver = ->(request) do
3+
# in production, we're using a two-level subdomain like "tenant.fizzy.37signals.com", but in
4+
# development and beta it's only a single-level subdomain.
5+
tld_length = request.domain == "37signals.com" ? 2 : 1
6+
request.subdomain(tld_length)
7+
end
48
end
59

610
ActiveSupport.on_load(:action_controller_base) do

0 commit comments

Comments
 (0)