3
3
require "modal_responder"
4
4
5
5
class ApplicationController < ActionController ::Base
6
- set_current_tenant_by_subdomain ( :organization , :subdomain )
6
+ # set_current_tenant_by_subdomain(:organization, :subdomain)
7
7
8
8
include Authentication
9
9
include Pundit
10
10
11
11
rescue_from ActiveRecord ::RecordNotFound , with : :render_not_found
12
12
rescue_from Pundit ::NotAuthorizedError , with : :user_not_authorized
13
13
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
15
15
16
16
# See `lib/modal_responder.rb` for deatils.
17
17
def respond_modal_with ( *args , &blk )
@@ -27,6 +27,10 @@ def render_not_found
27
27
28
28
private
29
29
30
+ def current_tenant
31
+ ActsAsTenant . current_tenant
32
+ end
33
+
30
34
def redirect_notenant
31
35
redirect_to home_index_path if ActsAsTenant . current_tenant . nil?
32
36
end
@@ -41,6 +45,14 @@ def set_admin_org
41
45
@admin_org = ActsAsTenant . current_tenant &.admin?
42
46
end
43
47
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
+
44
56
def set_version
45
57
@version = ""
46
58
fn = File . join ( Rails . root , "deploy" , "deploy_hash" )
0 commit comments