class TagBuilder

Ruby on Rails 2.0.23

Since v1.3.3 Last seen in v2.0.23

Available in: v1.3.3 v1.4.0 v1.5.0 v2.0.23

This 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

Object

Includes

Methods (defined here)

Private methods

(2) Implementation detail — not part of the public API.

Methods (inherited)

From Turbo::Streams::ActionHelper (2)

Type at least 2 characters to search.

↑↓ navigate · open · esc close