Patch Turbo to use the request script name

so that the URLs generated during view rendering are correct
This commit is contained in:
Mike Dalessio
2025-06-26 15:05:33 -04:00
parent 33d5eccb70
commit e68e2eb971
+19
View File
@@ -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