“从购物车中删除产品”按钮不起作用

时间:2019-02-28 13:04:53

标签: ruby-on-rails ruby spree

我在Spree应用中从购物车按钮删除产品时遇到问题。 我有购物车,并且有部分_line_item.html.erb:

<%= order_form.fields_for :line_items, line_item do |item_form| %>
  <tr class="first odd">
    <td class="image"><a class="product-image" title="Sample Product" href="#/women-s-crepe-printed-black/">
      <% if variant.images.length == 0 %>
        <%= link_to small_image(variant.product), variant.product %>
      <% else %>
        <%= link_to image_tag(variant.images.first.attachment.url(:small)), variant.product %>
      <% end %>
    </td>
    <td><h2 class="product-name">
      <%= link_to line_item.name, product_path(variant.product) %>
       </h2>
    </td>
    <td class="a-center"><a title="Edit item parameters" class="edit-bnt" href="#configure/id/15945/"></a></td>
    <td class="a-right"><span class="cart-price"> <span class="price">
      <%= line_item.single_money.to_html %></span> </span>
    </td>
    <td class="a-center movewishlist">
      <%= item_form.number_field :quantity, min: 0, class: "form-control line_item_quantity", size: 5 %>
    </td>
    <td class="a-right movewishlist"><span class="cart-price"> <span class="price">
      <%= line_item.display_amount.to_html unless line_item.quantity.nil? %></span> </span>
    </td>
    <td class="a-center last cart-item-delete ">
      <%= link_to content_tag(:span, '', class: 'glyphicon glyphicon-minus-sign'), '#', class: 'delete', id: "delete_#{dom_id(line_item)}" %>
    </td>
  </tr>

<% end %>

最后一个表格单元格是指从购物车按钮中删除产品,但是当单击该商品时,该购物车没有任何反应

<%= link_to content_tag(:span, '', class: 'glyphicon glyphicon-minus-sign'), '#', class: 'delete', id: "delete_#{dom_id(line_item)}" %>

2 个答案:

答案 0 :(得分:0)

考虑添加

<%= javascript_include_tag "application" %>

到layouts / spree_application.html.erb

此外,请确保添加资产管道... assets / javascripts / spree / frontend.js看起来像这样

    //= require jquery
    //= require jquery_ujs 
    //= require spree
    //= require spree/frontend/checkout
    //= require spree/frontend/product
    //= require spree/frontend/cart
    //= require spree/frontend/locale_selector

此应与以下项配合正常

'<%= link_to content_tag(:span,``,class:'glyphicon glyphicon-minus-sign'),'#',class:'delete',id:“ delete _#{dom_id(line_item)}”“ %>'

答案 1 :(得分:0)

可能有效:

<%= link_to content_tag(:span, '', class: 'glyphicon glyphicon-minus-sign'), line_item_path(line_item), method: :delete, class: 'delete', id: "delete_#{dom_id(line_item)}" %>