Rails7中销毁嵌套资源的link_to为何同时尝试删除父资源?
Rails7中销毁关联模型后意外触发父模型DELETE请求的问题
我有两个模型:site和heading,site与heading为一对多(has_many)关联。我编写了如下销毁链接代码:
<%= link_to site_heading_path(@site, @heading), data: { 'turbo-method': :delete, 'turbo-confirm': "Are you sure?"} do %> <i class="ti ti-trash"></i> Destroy <% end %>
headings控制器的destroy方法为默认生成的代码:
def destroy @heading.destroy respond_to do |format| format.html { redirect_to site_path(@site), notice: "Heading was successfully destroyed." } format.json { head :no_content } end end
这段代码我曾多次编写,但在全新的Rails7基础项目中出现异常。
预期行为
删除heading后,重定向到/sites/1
实际行为
heading被删除(正常)- 重定向生效(正常)
- TURBO_STREAMS意外调用
/sites/1的DELETE请求(异常)
我不清楚该问题产生的原因,webrick输出显示系统尝试删除site——请求记录中出现针对/sites/1的DELETE请求,发起者为Turbo Streams。
内容的提问来源于stack exchange,提问作者Matthew Rathbone
相关产品推荐
相关产品推荐

