ruby-on-railsturbo

Calling a turbo stream from within another one


I have the two turbo stream views below:

# flash.turbo_stream.erb
<%= turbo_stream.append "flash", partial: "layouts/flash" %>
# create.turbo_stream.erb
<%= turbo_stream.update "header" do %>
  <p>Lorem Ipsum</P>
<% end %>

# Flash goes here

Is there a way from within create to call the flash turbo stream?


Solution

  • .turbo_stream is a format extension, you can still do normal erb things:

    # create.turbo_stream.erb
    
    <%= turbo_stream.update "header" do %>
      Lorem Ipsum
    <% end %>
    
    # renders _flash.turbo_stream.erb
    <%= render "flash" %>
    
    # renders shared/flash.turbo_stream.erb
    <%= render template: "shared/flash" %>