Consider the current tenant in email URLs

This commit is contained in:
Javi Martín
2022-09-24 15:14:12 +02:00
parent 5983006657
commit 275ddb08d8
3 changed files with 66 additions and 0 deletions

View File

@@ -6,7 +6,25 @@ class ApplicationMailer < ActionMailer::Base
layout "mailer"
before_action :set_asset_host
def default_url_options
if Tenant.default?
super
else
super.merge(host: host_with_subdomain_for(super[:host]))
end
end
def set_asset_host
self.asset_host ||= root_url.delete_suffix("/")
end
private
def host_with_subdomain_for(host)
if host == "localhost"
"#{Tenant.current_schema}.lvh.me"
else
"#{Tenant.current_schema}.#{host}"
end
end
end