0

当用户单击破坏两个产品之间关系的按钮时,我试图通过 ajax 呈现部分内容。破坏动作有效,但我无法使部分渲染工作。

部分呈现在产品的编辑页面上:

编辑.html.erb

<div id="relationship_form">
  <%= render "relationships", product: @product %>
</div>

_relationships.html.erb

<%= render "unrelate", relationship: relationship %>

_unrelate.html.erb

<%= form_for(relationship,html: { method: :delete },remote: true) do |f| %>
  <%= f.submit "Remove", class: "btn btn-small" %>
<% end %>

关系控制器.html.erb

def destroy
...
 respond_to do |format|
  format.html { redirect_to edit_product_path }
  format.js
 end
end

销毁.js.erb

$("#relationship_form").html("<%= escape_javascript(render :partial => 'products/relationships', :locals => {:product => @product}) %>");

我已经通过插入警报检查了ajax调用是否通过了destroy.js.erb,所以javascript中一定有错误吗?

更新

我通过将 _unrelate 部分中的表单移动到 _relationship 部分来使其工作。仍然不清楚为什么它使它起作用。

_relationships.html.erb

<%= form_for(relationship,html: { method: :delete },remote: true) do |f| %>
  <%= f.submit "Remove", class: "btn btn-small" %>
<% end %>
4

0 回答 0