javascript - Rails - Handling custom attributes in AJAX response -
i have shopping cart multiple items display @ checkout giving users ability delete items if required. page has count of total items in cart trying update after item deleted. 500 server response code.
how correctly return remaining items , update on html page?
##app/controllers/items_controller.rb def destroy @item = current_user.cart.find(params[:id]) @item.destroy if @item.destroyed? render :status => 200, :json => {:success => true,:remaining => "#{pluralize(current_user.cart.count, 'item')}" } end end
and javascript file -
##app/assets/javascripts/cart.js.coffee jquery ($) -> $(".delete-link").bind "ajax:success", -> $("#cart-count").html(data.remaining) $(this).closest("tr").fadeout() return
Comments
Post a Comment