# How does form\_with know to use content type "text/html; turbo-stream"

**URL:** <https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508>\
**Category:** General\
**Created:** [March 14, 2021, 10:09pm UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508 "2021-03-14T22:09:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greenspud](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/greenspud/32/1767_2.png) [@greenspud](https://discuss.hotwired.dev/u/greenspud)\
**Post date:** [March 14, 2021, 10:09pm UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508/1 "2021-03-14T22:09:25Z")

</div>

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](https://github.com/hotwired/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?

---

<div class="post-metadata">

**Author:** ![dan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/dan/32/1529_2.png) [@dan](https://discuss.hotwired.dev/u/dan)\
**Post date:** [March 15, 2021, 9:23pm UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508/2 "2021-03-15T21:23:34Z")

</div>

This doesn’t happen in Rails actually. Turbo handles this.

When you submit your forms with Turbo Drive, it adds an `Accepts` header to tell servers they can return a turbo stream in response. You can see the code [here](https://github.com/hotwired/turbo/blob/main/src/core/drive/form_submission.ts#L113-L121).

Rails already has logic to pick apart the `Accepts` header, which is what powers the [`respond_to` method](https://api.rubyonrails.org/classes/ActionController/MimeResponds.html#method-i-respond_to) in your Rails controllers.

---

<div class="post-metadata">

**Author:** ![greenspud](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/greenspud/32/1767_2.png) [@greenspud](https://discuss.hotwired.dev/u/greenspud)\
**Post date:** [March 16, 2021, 5:50am UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508/3 "2021-03-16T05:50:48Z")

</div>

Thanks for helping me find where this occurs in the code. It seems that the default convention now is that if Turbo is enabled, it is assumed that all form requests should be expected to be treated like a Turbo request by the backend Rails app in the `respond_to` responder. Am I understanding that correctly?

I can’t think of a circumstance right now why you’d want to turn it off and go back to a regular `Accept: text/html` type of form, but I’m taking that it’s not configurable?

---

<div class="post-metadata">

**Author:** ![dan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/dan/32/1529_2.png) [@dan](https://discuss.hotwired.dev/u/dan)\
**Post date:** [March 16, 2021, 7:59am UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508/4 "2021-03-16T07:59:18Z")

</div>

yep that’s right: Turbo will add the header to all form submissions, unless they’re GET requests.

There’s no way to opt out, without disabling Turbo for the form, a la `data-turbo=“false”`.

---

<div class="post-metadata">

**Author:** ![leehericks](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/leehericks/32/1053_2.png) [@leehericks](https://discuss.hotwired.dev/u/leehericks)\
**Post date:** [March 18, 2021, 10:18am UTC](https://discuss.hotwired.dev/t/how-does-form-with-know-to-use-content-type-text-html-turbo-stream/2508/5 "2021-03-18T10:18:59Z")

</div>

Question:

Why do you use `target: "_top"`? Doesn’t that force your whole page to reload?
