I’m working on an app with a “load more items” functionality where more things will get displayed on a list if a user clicks a button. Turbo stream append seems to be the appropriate tool for this, but I’m having trouble figuring out the Hotwire way of triggering the request. To get a better understanding I’ve taken a look at the Hotwire Rails Demo Chat and noticed that on the new message form, the form_with
call always submits with the content type “text/html; turbo-stream” that tells Rails to process the POST message as a TURBO_STREAM. I don’t see any flags in the code where it specifies to do this. How is this magic happening?
Here’s what the form looks like for reference:
<%= turbo_frame_tag "new_message", target: "_top" do %>
<%= form_with(model: [ @message.room, @message ],
data: { controller: "reset_form", action: "turbo:submit-end->reset_form#reset" }) do |form| %>
<div class="field">
<%= form.text_field :content %>
<%= form.submit "Send" %>
</div>
<% end %>
<% end %>
I tried replicating this form without the turbo_frame_tag
and it somehow still knew to submit as a TURBO_STREAM. Could someone explain what’s happening here?