'Render inside turbo_stream template tag

Why rendering partial inside <template> tags of stream.erb file raises ActionView::MissingTemplate error?

For example in some_action_in_controller.turbo_stream.erb file i have;

<turbo-stream action="some_action" target="some_target">
  <template>
    <div class="some-class">
      <% @some_records.each do |r|
       <%= render partial: 'some_partial', locals: { data_to_partial } %>
      <% end% >
    </div>
  </template>
</turbo-stream>

In this case i use <turbo-stream> tag instead of <%= turbo_stream.. %> since in my stream file, i render more than just a partial to maintain the UI in page where i am streaming the data.

Why am i getting the error? and what is actually happening?



Solution 1:[1]

You can also change your partial's format, rename from:

some_partial.html.erb to some_partial.turbo_stream.erb.

Specifying the format: [:html] on render didn't work for me on rails 7.0.2.4, turbo-rails 1.0.1.

Solution 2:[2]

Add formats: [:html] to the render statement. Note that this is formats plural, unlike the previous answers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Parker
Solution 2 Brendon