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?
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 } %>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With