I ran the following in the command line:
> rails new test-turbo
> rails g controller Home index
Added the following route to config/routes.rb
:
resources :home, only: [:index]
Wrapped the <%= yield %>
in app/views/layouts/application.html.erb
in a turbo frame tag:
<body>
<%= turbo_frame_tag :foobar do %>
<%= yield %>
<% end %>
</body>
Added a link in app/views/home/index.html.erb
:
<%= link_to "Link to this page", home_index_path %>
Then, when clicking on that link, I get a turbo frame error:
If I move the turbo frame tag into the home/index page, it works fine:
app/views/home/index.html.erb
<%= turbo_frame_tag :foobar do %>
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<%= link_to "Link to this page", home_index_path %>
<% end %>
Why does this work, but putting it in app/views/layouts/application.html.erb
doesn't work? It's generating the same HTML at the end of the day, right?
In case its helpful, here's the GitHub repo. Commit 537c40a
has the error, commit b42ca66
works fine.
Update: here's a gif displaying a solution that works with two turbo frames, one that is persistent across pages: