0

我正在尝试更新购物车中订单的属性。为此,我想使用 best_in_place gem ( https://github.com/bernat/best_in_place )的就地编辑
无论如何,一旦它被实施,它不会更新提交记录。

这是我的看法:

= form_for @order, :url => update_cart_path, :html => {:id => 'update-cart'} do |order_form|
%div#line_items_list
  - @order.line_items.each do |line_item|
    %section#line-item.columns.twelve
      %div.line_picture.columns.three.alpha
        %div#line_picture
          = image_tag(line_item.variant.images.first.attachment.url(:product)) unless line_item.variant.images.length == 0
      %div#line_description.nine.columns.omega
        %span#line_title.nine.columns
          %span.columns.alpha= full_product_name(line_item.variant)
          %span#line_price.offset-by-five.columns.omega= money line_item.price
        %div#optionsvariant
          - if line_item.variant.option_values.any?
            - line_item.variant.sorted_values.each do |ov|
              %div#line_item_options
                %span= ov.option_type.presentation
                - if ov.swatch?
                  %span.imagelabel= image_tag("#{ov.swatch.url(:circle)}")
                - else
                  %span.textlabel.not_selected= ov.presentation
          %div#orderquantity
            Quantity
            = best_in_place [@order, line_item], :quantity, :type => :input
          - if line_item.subscription_line?
            %p#subline Auto ship: first pair ships today and every 1 month.

这是我的控制器更新 aciton:

def update
@order = current_order
  respond_to do |format|
    if @order.update_attributes(params[:order])
      format.html do
        @order.line_items = @order.line_items.select {|li| li.quantity > 0 }
        fire_event('spree.order.contents_changed')
        respond_with(@order) { |f| f.html { redirect_to cart_path } }
      end

      format.json { respond_with_bip(@order)}
    else
      format.html {respond_with(@order)}
      format.json {respond_with_bip(@order)}

    end
  end
end

这样做的正确方法是什么,所以它会更新购物车中我的 Line_item 的数量?

4

1 回答 1

1

删除

= form_for @order, :url => update_cart_path, :html => {:id => 'update-cart'} 做 |order_form|

从表格顶部解决了这个问题。

于 2012-11-14T07:50:24.623 回答