hey everyone
I’m a bit confused with something: I have a create action that was rendering a partial upon a successful response. something like this:
<%= turbo_frame_tag 'new-message-form' do %>
<%= form_tag messages_path, data: { action: 'turbo:submit-start->loader#started turbo:submit-end->loader#finished ' } do %>
<% end %>
def create
message.encrypt!(password: params[:password])
render partial: "messages/tada", locals: { message: }
end
and the partial had this content:
<%= turbo_frame_tag "new-message-form" do %>
<div data-controller="...
<% end %>
and this is/was working fine, the whole frame gets replaced by the contents of the partial.
I decided to get rid of this partial and moved the content of this partial to create.turbo_stream.erb
but I noticed that upon a successful request, the content of the create.turbo_stream.erb
was getting appended to end of the body.
I fixed by using <%= turbo_stream.replace "new-message-form" do %>
in the file but now I’m confused and I have a question: why does the partial replaces the contents just fine while using the create.turbo_stream.erb
way forces me to explicit tells turbo what to replace? that goes against every example I see on the web, where Turbo is smart enough to match the response’s turbo frame tag id with the one in the form and automatically replace it.
I do not have any special configuration or something in my application.js
file too