what i did was
1. add format.js in carts controller destroy method
2. add remote: true on empty button
3. create destroy.js.erb in views/carts with
$('#cart').html("<%=j render @cart %>").hide('blind', 1000);
it works fine but seems not following given hint…
Does the cart appear when you access the page at first?
Does the cart appear after you empty the cart and reload the page?
@ys: in your 3rd step i did this:
$('#cart tr').not('.total_line').remove(); $('#cart').hide('blind', 1000);
@michael: why do we need to use the .not. I had used only the #cart.hide but that did not work after emptying the cart and then adding to it again. However, your solution works great. Can you explain this a little more please?
@jack: The reason you use the not() is to remove all tr entires from the table, except for #total_line. The reason you want to do this is because in create.js.erb we told the browser to show() the cart if, and only if the number of tr entires under #cart is 1.