best_in_place gem不会更新关联的记录

时间:2012-11-13 19:35:25

标签: ruby-on-rails spree best-in-place

我正在尝试更新购物车中订单的属性。为此,我想使用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的数量?

1 个答案:

答案 0 :(得分:1)

删除

  

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

从表单顶部解决了问题。