I am getting a problem when I am trying to remove an item from the cart
using Ajax. I have a view named display_cart.rhtml, a controller
store_controller.rb and a model cart.rb. I have written a method named
remove_from_cart in store_controller.rb and javascript in
display_cart.rhtml to display total cost after deleting the item from
the cart.
The method is:
def remove_from_cart
product = Product.find(params[:id]) @cart = find_cart @cart.remove_product(product)
redirect_to :action => “display_cart” and return false
end.
Now the output it is showing is:
Display Cart
* Continue Shopping
* Empty Cart
* Checkout
Qty Description Price
Each Total
1 abc $10.00 $10.00 remove product
1 abc $10.00 $10.00 remove product
Total: Total:20
Display Cart
* Continue Shopping
* Empty Cart
* Checkout
Qty Description Price
Each Total
1 abc $10.00 $10.00 remove product
1 abc $10.00 $10.00 remove product
1 a $10.00 $10.00 remove product
Total: $30.00.
It is displaying the results as many times as I remove the items. Can
anyone tell me what is the exact problem.
the cart.
The method is:
def remove_from_cart
product = Product.find(params[:id]) @cart = find_cart @cart.remove_product(product)
redirect_to :action => “display_cart” and return false
end.
This is probably to do with the bit you haven’t show us :-), ie
whether your link_to_remote is set to update a div (which one?) and
what is in display_cart.rhtml
the cart.
The method is:
def remove_from_cart
product = Product.find(params[:id]) @cart = find_cart @cart.remove_product(product)
redirect_to :action => “display_cart” and return false
end.
This is probably to do with the bit you haven’t show us :-), ie
whether your link_to_remote is set to update a div (which one?) and
what is in display_cart.rhtml
Fred
yeah… link_to_remote is set to update a div named ‘tablecart’. This
is the method in display_cart and a div named ‘tablecart’ which contains
table having product name, quantity and price.
don’t use :position => ‘top’: that means ‘add the returned content to
the top of the named div’, whereas what you want is to replace the
content of the named div
don’t use :position => ‘top’: that means ‘add the returned content to
the top of the named div’, whereas what you want is to replace the
content of the named div
Fred
Thanks a lot Fred. This problem is removed. But one more thing. When I
again click
on add_to_cart… the total comes out be to be the previous total i.e
total before
deletion of item + the new products total.