2

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?

István Ujj-Mészáros
  • 3,228
  • 1
  • 27
  • 46
googlesnet
  • 85
  • 9
  • For anyone who is stuck on this, a way to achieve this was to simply append `format: [:html]` parameter inside the render tag. Eg, `<%= render partial: 'some_partial', locals: { data_to_partial }, format: [:html] %>` And there you go, you get the partial working inside stream. Hope it helps! :)))) – googlesnet Jan 30 '22 at 16:54

2 Answers2

2

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

<%= render partial: 'some_partial', formats: [:html], locals: { data_to_partial } %>
István Ujj-Mészáros
  • 3,228
  • 1
  • 27
  • 46
Brendon
  • 879
  • 1
  • 6
  • 18
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.

Tim Parker
  • 31
  • 1