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.

What do you mean it was a PICNIC error? Can you please elaborate on what solved it for you? This answer is appearing in Google results so it might be useful.

PICNIC = Problem in chair, not in computer

It basically means it was my fault. :sweat_smile:

I don’t remember though what it was, this was almost 4 years ago…

Ha! Cool, no worries, thanks for answering!

I’ve also heard this as PEBKAC: problem exists between keyboard and chair.

Walter