# Emptying cart

**URL:** <https://www.ruby-forum.com/t/emptying-cart/184278>\
**Category:** Deployment\
**Created:** [February 28, 2010, 1:11am UTC](https://www.ruby-forum.com/t/emptying-cart/184278 "2010-02-28T01:11:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexpescara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b487fb/32.png) [@alexpescara](https://www.ruby-forum.com/u/alexpescara)\
**Post date:** [February 28, 2010, 1:11am UTC](https://www.ruby-forum.com/t/emptying-cart/184278/1 "2010-02-28T01:11:24Z")

</div>

hi.  
i’m new to ruby on rails  
I have a big problem  
I’m writing a program wich has a Product class(active record) wich  
contains the product I want to sell…and a Cart class where i save the  
Products I want to buy…each product has a availability field that i  
decrement when I add the product to the cart…  
Now  
if I empty the cart by clicking a link I can empty the cart and restore  
the right availability for each product that was in the cart before  
but if I close the browser with the cart not empty, it gets empty, but  
the availability is not restored correctly

Is there a way to fix this problem? is there a way to ‘intercept’ the  
termination of the browser? or an event that is called at the  
application terminate? or a decontructor method for my class Cart?

i red something browsing the web but I was unable to fix this problem

please help me  
thanks
