change default layout for turbo frame request
Rails
When Turbo-Frame header is present in request Rails substitute application layout for minimal layout (as of 2025-09-05 this was) :
<html> <head> <%= csrf_meta_tags %> <%= yield :head %> </head> <body> <%= yield %> </body> </html>
https://github.com/hotwired/turbo-rails/blob/main/app/views/layouts/turbo_rails/frame.html.erb
This is merely a rendering optimization. Everything would still work just fine if we rendered everything including the full layout. Turbo Frames knows how to fish out the relevant frame regardless.
The layout used is turbo_rails/frame.html.erb. If there’s a need to customize this layout: you can add app/views/layouts/turbo_rails/frame.html.erb to project and update that
source https://rubydoc.info/github/hotwired/turbo-rails/Turbo/Frames/FrameRequest
---
Note :
in the past I though that Rails by default uses no layout when turbo frame header request hits the server, so equivalent to
layout -> { false if turbo_frame_request? }
Nope, this is not the case, this is wrong.
Yes you can do `render :foo, layout: false` in your controller , but that's just different usecase
Yes you can do `render :foo, layout: false` in your controller , but that's just different usecase