0
我試圖從購物車內的訂單更新屬性。爲此,我希望使用best_in_place gem(https://github.com/bernat/best_in_place)
進行就地編輯,無論如何,一旦它被實現,它就不會在提交時更新記錄。best_in_place gem不會更新關聯的記錄
這是我的看法:
= 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的數量在購物車?