Hi, I was watching this video yesterdy and at 5:50 he added a turbo_stream format.
What confused me is how does the app know it’s a turbo_stream format? I didn’t notice anything being added to the form to indicate that? How does it differentiate from a standard HTML format?
If you try it out - you’ll see
What you’ll (hopefully) see is that when submitting the message form, (in the terminal where your ‘rails server’ process is running) a line with something like
Started POST "/messages" for ::1 at 2022-11-25 13:09:28 +0100
Processing by MessagesController#create as TURBO_STREAM
(it might not necessarily be exactly like the above, but close enough I’d say -
that’s my understanding at least
Thanks for that, I understand all the flow, just not the part where the form switches from a standard post request to an ajax request via Turbo?
I understand every other part but there’s that one gap that i’m obviously missing.
the - beauty if you will - of Hotwire is exactly that.
It starts out as standard get/post and all of a sudden it “transmogifs” into something else (turbo)
it’s at your discretion to deactivate the turbo part simply by adding an attribute to the submit button telling it to not submit as turbo - and then it will post as standard
<form action="/messages" method="post" data-turbo="false">
Try that - and see the difference in your terminal
Thought it might be worth noting some of the finer details/mechanics. If you inspect the Network requests while submitting a Turbo-enabled form, you’ll see in the HTTP Headers that the
Accept is set to
text/vnd.turbo-stream.html. You’ll also see this same value on the HTTP Headers of the response as the
Directly from the handbook,
When submitting a
<form> element whose method attribute is set to
PATCH , or
DELETE , Turbo injects
Accept HTTP Header on the request is what Rails uses to determine that the request has been via