Turbo Frame modal that renders server HTML

9231
0

When I need a modal (new/edit/show), I avoid client-side templating by using a dedicated turbo_frame_tag as the modal container (often id='modal'). Links target that frame, so the response only replaces the modal content. Closing the modal is just swapping it back to an empty shell. The key trick is to ensure the modal response renders without the full layout when it’s a frame request (use turbo_frame_request?). This keeps DOM diffing small and avoids nesting <html> inside a frame. I also like placing the modal frame once in application.html.erb so every page can open modals without duplicated markup.