如何使用 Turbo 框架将对象创建表单替换为对象显示部分?
我有一个模型 subscription_tier
,其中包含 show
和 edit
操作以及相应的视图。我已经用 Turbo 框架包裹了每一个
<%= Turbo_frame_tag subscription_tier do %>
当我编辑现有订阅层并保存它时,turbo 框架会刷新并显示我保存的层,但我无法复制此内容以创建新层。
我的新层框架:
<turbo-frame id="new_tier">
<%= link_to "Add Tier", new_create_subscription_tier_path(sub_type: "Free"), class: "btn btn-primary mb-3 fs-6"
%>
</turbo-frame>
在 new.html.erb
中,
<turbo-frame id="new_tier">
<%= render partial: "create/subscription_tiers/edit", locals: {
subscription_tier: @subscription_tier
} %>
</turbo-frame>
单击“添加层”按钮成功呈现表单,我可以保存对象,但在保存时,turbo 框架被破坏,并出现错误 Response has没有匹配的
我知道这是因为我的 show
部分是用 <%= Turbo_frame_tag subscription_tier do %>
包装的,但我不知道如何调和这一点。
I have a model subscription_tier
with show
and edit
actions with corresponding views. I've wrapped each of these with a turbo frame
<%= turbo_frame_tag subscription_tier do %>
When I edit an existing subscription tier and save it, the turbo frame refreshes and shows my saved tier, but I'm unable to replicate this for creating new tiers.
My new tier frame:
<turbo-frame id="new_tier">
<%= link_to "Add Tier", new_create_subscription_tier_path(sub_type: "Free"), class: "btn btn-primary mb-3 fs-6"
%>
</turbo-frame>
and in new.html.erb
<turbo-frame id="new_tier">
<%= render partial: "create/subscription_tiers/edit", locals: {
subscription_tier: @subscription_tier
} %>
</turbo-frame>
Clicking Add Tier button successfully renders the form and I can save the object, but on save the turbo frame is destroyed with the error Response has no matching <turbo-frame id="new_tier"> element
I know this is because my show
partial is wrapped with the <%= turbo_frame_tag subscription_tier do %>
, but I don't know how to reconcile this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您需要在新链接中添加一个数据标签,即
在与此链接相同的页面上 ^^^^ 您需要添加
我相信这就是您想要完成的任务
有一个很棒的教程,涵盖了所有这些内容此处免费
I believe you need to add a data tag to your new link i.e.
On the same page as this link ^^^^ you need to add
I believe this is what your trying to accomplish
There is a fantastic tutorial that goes over all this stuff that is free here
也许OP已经解决了这个问题,但是对于任何寻找可能解决方案的人来说,您总是可以手动设置turbo帧ID,例如:
并且
这会将事物保留在同一个turbo帧中。
Perhaps the OP figured this out, but for anyone looking for a possible solution, you could always set the turbo frame ID manually, for example:
and
That'll keep things in the same turbo frame.