diff --git a/app/channels/turbo/streams/broadcasts.rb b/app/channels/turbo/streams/broadcasts.rb index 5b4aba97..eca4f631 100644 --- a/app/channels/turbo/streams/broadcasts.rb +++ b/app/channels/turbo/streams/broadcasts.rb @@ -38,18 +38,9 @@ def broadcast_refresh_to(*streamables, **opts) end def broadcast_action_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering) - content = rendering.delete(:content) - html = rendering.delete(:html) - render = rendering.delete(:render) - - template = - if render == false - nil - else - content || html || (render_format(:html, **rendering) if rendering.present?) - end - - broadcast_stream_to(*streamables, content: turbo_stream_action_tag(action, target: target, targets: targets, template: template, **attributes)) + broadcast_stream_to *streamables, content: turbo_stream_action_tag( + action, target: target, targets: targets, template: render_broadcast_action(rendering), **attributes + ) end def broadcast_replace_later_to(*streamables, **opts) @@ -119,4 +110,17 @@ def refresh_debouncer_for(*streamables, request_id: nil) # :nodoc: def render_format(format, **rendering) ApplicationController.render(formats: [ format ], **rendering) end + + def render_broadcast_action(rendering) + content = rendering.delete(:content) + html = rendering.delete(:html) + render = rendering.delete(:render) + + template = + if render == false + nil + else + content || html || (render_format(:html, **rendering) if rendering.present?) + end + end end