ショッピングカート内の注文から属性を更新しようとしています。そのためには、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の数量を更新するための適切な方法はどのようになりますか?