instance method turbo_stream

Ruby on Rails 1.3.3

Since v1.3.3 Last seen in v2.0.23

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

Signature

turbo_stream()

Returns a new Turbo::Streams::TagBuilder object that accepts stream actions and renders them as the template tags needed to send across the wire. This object is automatically yielded to turbo_stream.erb templates.

When responding to HTTP requests, controllers can declare turbo_stream format response templates in that same style as html and json response formats. For example, consider a MessagesController that responds to both text/html and text/vnd.turbo-stream.html requests along with a .turbo_stream.erb action template:

def create
  @message = Message.create!(params.require(:message).permit(:content))
  respond_to do |format|
    format.turbo_stream
    format.html { redirect_to messages_url }
  end
end

<%# app/views/messages/create.turbo_stream.erb %>
<%= turbo_stream.append "messages", @message %>

<%= turbo_stream.replace "new_message" do %>
  <%= render partial: "new_message", locals: { room: @room } %>
<% end %>

When a app/views/messages/create.turbo_stream.erb template exists, the ‘MessagesController#create` will respond to text/vnd.turbo-stream.html requests by rendering the messages/create.turbo_stream.erb view template and transmitting the response

Source
# File app/helpers/turbo/streams_helper.rb, line 27
  def turbo_stream
    Turbo::Streams::TagBuilder.new(self)
  end

Defined in app/helpers/turbo/streams_helper.rb line 27 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Turbo::StreamsHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close