Hotwire Discussion

Response uses Content-Type "turbo-stream", even though template suffix is ".html.erb"

After a redirect in response to a form submission with Turbo, the page is requested with Accept header “text/vnd.turbo-stream.html, text/html, application/xhtml+xml”. So far, so good.

I want to return HTML, so I add

render template: "my_template"

to the controller action and create a template named “my_template.html.erb”.

The “.html.erb” suffix should tell Rails to set the Content-Type header to “text/html”, right?
It doesn’t, instead “text/vnd.turbo-stream.html” is used.

Do I really need to explicitly write

respond_to do |format|
  format.html { render template: "my_template" }
end

instead of just

render template: "my_template"

Why isn’t the template suffix enough to tell Rails to return HTML instead of Turbo Stream?

Please ignore, this was a PICNIC error.