だから私は@cartに属する@line_itemsを持っています。ページを更新せずにカートを空にしたい。カートテンプレートにbutton_toを設定しました
<%= button_to 'Empty cart' , cart, :remote => true, :method => :delete,
:confirm => 'Are you sure?' %>
carts_controllerのdestroyメソッド
def destroy
@cart = current_cart
@cart.line_items.destroy
session[:cart_id] = nil
respond_to do |format|
format.html { redirect_to(store_url, :notice => 'Your cart is currently empty' ) }
format.js
format.xml { head :ok }
end
end
およびdestroy.js.erb
$('#cart').html("<%= escape_javascript(render(@cart)) %>");
リフレッシュ後にのみ機能します。ボタンを押すとカートが空になると思いますので、レールが@cartをレンダリングすると、カートは空で表示されます。多分私は何かが間違っていますか?