# How to do "delete item" AJAX

**URL:** <https://www.ruby-forum.com/t/how-to-do-delete-item-ajax/115177>\
**Category:** Deployment\
**Created:** [September 21, 2007, 11:35am UTC](https://www.ruby-forum.com/t/how-to-do-delete-item-ajax/115177 "2007-09-21T11:35:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 21, 2007, 11:35am UTC](https://www.ruby-forum.com/t/how-to-do-delete-item-ajax/115177/1 "2007-09-21T11:35:47Z")

</div>

if we add an item to the shopping cart, the AJAX is easy:

the View adds an item to the cart, and also set the “current\_item\_added”  
and then just let the view (RJS) update the whole cart content, and then  
blink the current\_item\_added, and that’s it.

but what about now it is deleting an item, and it is the last item in  
the cart, so how do you let the Controller find that item, and let the  
View blink it, and then come back to the Controller to delete that item,  
and then go to the View again to update the new cart?

I can think of letting the Controller dup the original cart first as  
old\_cart(need deep copy?), and then passing the following to the View:

1. current\_item\_deleted
2. old\_cart
3. new\_cart

and then let the RJS blink the current\_item\_deleted with the old\_cart,  
and then, display the cart using new\_cart.

is this not proper, or is there a proper MVC way?
