From e68e2eb97111ddfd60bc989e3012977f57829069 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 26 Jun 2025 15:05:33 -0400 Subject: [PATCH] Patch Turbo to use the request script name so that the URLs generated during view rendering are correct --- config/initializers/tenanting.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/config/initializers/tenanting.rb b/config/initializers/tenanting.rb index a63b37caa..2c635a6bc 100644 --- a/config/initializers/tenanting.rb +++ b/config/initializers/tenanting.rb @@ -37,3 +37,22 @@ end ActiveSupport.on_load(:action_controller_base) do before_action { logger.struct tenant: ApplicationRecord.current_tenant } end + +module TurboStreamsJobExtensions + extend ActiveSupport::Concern + + class_methods do + def render_format(format, **rendering) + if ApplicationRecord.current_tenant + script_name = "/#{ApplicationRecord.current_tenant}" + ApplicationController.renderer.new(script_name: script_name).render(formats: [ format ], **rendering) + else + super + end + end + end +end + +Rails.application.config.after_initialize do + Turbo::StreamsChannel.prepend TurboStreamsJobExtensions +end