Skip to content

Commit e47a2d8

Browse files
authored
Merge pull request #302 from rubyforgood/subdomain-parse
fixed subdomain parsing
2 parents 48d4c7b + a3b8213 commit e47a2d8

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@ db/.DS_Store
3535

3636
# Ignore coverage files from simplecov
3737
/coverage
38-
39-
/deploy/deploy_hash

app/controllers/application_controller.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
require "modal_responder"
44

55
class ApplicationController < ActionController::Base
6-
set_current_tenant_by_subdomain(:organization, :subdomain)
6+
# set_current_tenant_by_subdomain(:organization, :subdomain)
77

88
include Authentication
99
include Pundit
1010

1111
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
1212
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
1313

14-
before_action :redirect_wrong_tenant, :redirect_notenant, :set_version, :set_admin_org
14+
before_action :set_tenant_by_subdomain, :redirect_notenant, :redirect_wrong_tenant, :set_version, :set_admin_org
1515

1616
# See `lib/modal_responder.rb` for deatils.
1717
def respond_modal_with(*args, &blk)
@@ -27,6 +27,10 @@ def render_not_found
2727

2828
private
2929

30+
def current_tenant
31+
ActsAsTenant.current_tenant
32+
end
33+
3034
def redirect_notenant
3135
redirect_to home_index_path if ActsAsTenant.current_tenant.nil?
3236
end
@@ -41,6 +45,14 @@ def set_admin_org
4145
@admin_org = ActsAsTenant.current_tenant&.admin?
4246
end
4347

48+
def set_tenant_by_subdomain
49+
subdomain = request.subdomains.first
50+
return if subdomain.nil?
51+
52+
tenant = Organization.find_by(subdomain: subdomain)
53+
ActsAsTenant.current_tenant = tenant
54+
end
55+
4456
def set_version
4557
@version = ""
4658
fn = File.join(Rails.root, "deploy", "deploy_hash")

config/environments/development.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363
config.action_mailer.delivery_method = :smtp
6464
config.action_mailer.smtp_settings = { address: 'mailcatcher', port: 1025 }
6565

66-
config.hosts << "midatlantic.lvh.me" << "acme.lvh.me" << "admin.lvh.me" << "lvh.me"
66+
config.hosts << "midatlantic.lvh.me" << "acme.lvh.me" << "admin.lvh.me" << "lvh.me" << "midatlantic.stage.lvh.me"
6767
end

deploy/deploy_hash

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
placeholder

0 commit comments

Comments
 (0)