You can use different html for a modal version of a view with Turbo by taking advantage of
view variants and the Turbo-Frame
header. This allows a page (like http://localhost:3000/widgets/1
) to show as a normal page OR to be loaded
using Turbo on another page into a modal window.
The turbo_action: 'advance'
on the link ensures the url updates to the new page.
The turbo_frame: 'modal'
on the link will slot the resulting page's turbo frame content inside the #modal
frame.
However, since we also use the Turbo-Frame
header to set our response variant, we will call the template
app/views/widgets/show.html+modal.erb
if it exists, otherwise falling back to app/views/widgets/show.html.erb
.
This allows us to customize the response for modal Turbo Frame requests if desired.