我在命令行中运行了以下命令:
> rails new test-turbo
> rails g controller Home index
将以下路由添加到config/routes.rb
:
resources :home, only: [:index]
将<%= yield %>
英寸app/views/layouts/application.html.erb
封装在Turbo帧标签中:
<body>
<%= turbo_frame_tag :foobar do %>
<%= yield %>
<% end %>
</body>
在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:
如果我将turbo帧标签移到主页/索引页面中,它可以正常工作:
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 %>
为什么这行得通,但放进app/views/layouts/application.html.erb
就不行了?它会在一天结束时生成相同的HTML,对吗?
如果有用的话,here's the GitHub repo.提交537c40a
有错误,提交b42ca66
工作正常.
Update: here's a gif displaying a solution that works with two turbo frames, one that is persistent across pages: