class TagBuilder
Ruby on Rails 2.0.23
Since v1.3.3 Last seen in v2.0.23This tag builder is used both for inline controller turbo actions (see Turbo::Streams::TurboStreamsTagBuilder) and for turbo stream templates. This object plays together with any normal Ruby you’d run in an ERB template, so you can iterate, like:
<% # app/views/postings/destroy.turbo_stream.erb %> <% @postings.each do |posting| %> <%= turbo_stream.remove posting %> <% end %>
Or string several separate updates together:
<% # app/views/entries/_entry.turbo_stream.erb %>
<%= turbo_stream.remove entry %>
<%= turbo_stream.append "entries" do %>
<% # format is automatically switched, such that _entry.html.erb partial is rendered, not _entry.turbo_stream.erb %>
<%= render partial: "entries/entry", locals: { entry: entry } %>
<% end %>
Or you can render the HTML that should be part of the update inline:
<% # app/views/topics/merges/_merge.turbo_stream.erb %> <%= turbo_stream.append dom_id(topic_merge) do %> <%= link_to topic_merge.topic.name, topic_path(topic_merge.topic) %> <% end %>
To integrate with custom actions, extend this class in response to the :turbo_streams_tag_builder load hook:
ActiveSupport.on_load :turbo_streams_tag_builder do def highlight(target) action :highlight, target end def highlight_all(targets) action_all :highlight, targets end end turbo_stream.highlight "my-element" # => <turbo-stream action="highlight" target="my-element"><template></template></turbo-stream> turbo_stream.highlight_all ".my-selector" # => <turbo-stream action="highlight" targets=".my-selector"><template></template></turbo-stream>
Inherits from
Includes
Methods (defined here)
- # action
- # action_all
- # after
- # after_all
- # append
- # append_all
- # before
- # before_all
- # prepend
- # prepend_all
- # refresh
- # remove
- # remove_all
- # replace
- # replace_all
- # update
- # update_all
- self. new