diff --git a/app/models/turbo/streams/tag_builder.rb b/app/models/turbo/streams/tag_builder.rb index b6032ab5..b375c18b 100644 --- a/app/models/turbo/streams/tag_builder.rb +++ b/app/models/turbo/streams/tag_builder.rb @@ -77,8 +77,8 @@ def remove_all(targets) # <%= turbo_stream.replace "clearance_5" do %> #
Replace the dom target identified by clearance_5
# <% end %> - def replace(target, content = nil, **rendering, &block) - action :replace, target, content, **rendering, &block + def replace(target, content = nil, attributes: {}, **rendering, &block) + action :replace, target, content, attributes: attributes, **rendering, &block end # Replace the targets in the dom with either the content passed in, a rendering result determined @@ -90,8 +90,8 @@ def replace(target, content = nil, **rendering, &block) # <%= turbo_stream.replace_all ".clearance_item" do %> #
Replace the dom target identified by the class clearance_item
# <% end %> - def replace_all(targets, content = nil, **rendering, &block) - action_all :replace, targets, content, **rendering, &block + def replace_all(targets, content = nil, attributes: {}, **rendering, &block) + action_all :replace, targets, content, attributes: attributes, **rendering, &block end # Insert the content passed in, a rendering result determined by the rendering keyword arguments, @@ -155,8 +155,8 @@ def after_all(targets, content = nil, **rendering, &block) # <%= turbo_stream.update "clearance_5" do %> # Update the content of the dom target identified by clearance_5 # <% end %> - def update(target, content = nil, **rendering, &block) - action :update, target, content, **rendering, &block + def update(target, content = nil, attributes: {}, **rendering, &block) + action :update, target, content, attributes: attributes, **rendering, &block end # Update the targets in the dom with either the content passed in or a rendering result determined @@ -168,8 +168,8 @@ def update(target, content = nil, **rendering, &block) # <%= turbo_stream.update_all "clearance_item" do %> # Update the content of the dom target identified by the class clearance_item # <% end %> - def update_all(targets, content = nil, **rendering, &block) - action_all :update, targets, content, **rendering, &block + def update_all(targets, content = nil, attributes: {}, **rendering, &block) + action_all :update, targets, content, attributes: attributes, **rendering, &block end # Append to the target in the dom identified with target either the content passed in or a @@ -241,17 +241,17 @@ def refresh(...) end # Send an action of the type name to target. Options described in the concrete methods. - def action(name, target, content = nil, allow_inferred_rendering: true, **rendering, &block) + def action(name, target, content = nil, attributes: {}, allow_inferred_rendering: true, **rendering, &block) template = render_template(target, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block) - turbo_stream_action_tag name, target: target, template: template + turbo_stream_action_tag name, target: target, template: template, **attributes end # Send an action of the type name to targets. Options described in the concrete methods. - def action_all(name, targets, content = nil, allow_inferred_rendering: true, **rendering, &block) + def action_all(name, targets, content = nil, attributes: {}, allow_inferred_rendering: true, **rendering, &block) template = render_template(targets, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block) - turbo_stream_action_tag name, targets: targets, template: template + turbo_stream_action_tag name, targets: targets, template: template, **attributes end private diff --git a/test/dummy/app/views/messages/show.turbo_stream.erb b/test/dummy/app/views/messages/show.turbo_stream.erb index 38b8eebb..1b35b598 100644 --- a/test/dummy/app/views/messages/show.turbo_stream.erb +++ b/test/dummy/app/views/messages/show.turbo_stream.erb @@ -2,6 +2,7 @@ <%= turbo_stream.replace @message %> <%= turbo_stream.replace @message, "Something else" %> <%= turbo_stream.replace "message_5", "Something fifth" %> +<%= turbo_stream.replace "message_5", "Something fifth", attributes: { method: :morph } %> <%= turbo_stream.replace "message_5", partial: "messages/message", locals: { message: Message.new(id: 5, content: "OLLA!") } %> <%= turbo_stream.append "messages", @message %> <%= turbo_stream.append "messages", partial: "messages/message", locals: { message: Message.new(id: 5, content: "OLLA!") } %> diff --git a/test/streams/streams_controller_test.rb b/test/streams/streams_controller_test.rb index 173626db..186bc451 100644 --- a/test/streams/streams_controller_test.rb +++ b/test/streams/streams_controller_test.rb @@ -23,6 +23,7 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest +