Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from ogredude/carts_controller.rb
Created July 14, 2011 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/1083250 to your computer and use it in GitHub Desktop.
Save tubbo/1083250 to your computer and use it in GitHub Desktop.
respond_to :html, :json
def update
@cart = Cart.find(params[:id])
@cart.update_attributes(params[:cart])
respond_with @cart
end
<script>
$(document).ready(function() {
$('input[type=checkbox]').change(function() {
$('#cart').fadeOut('fast', function() {
$.ajax({
url: '<%= update_store_cart_path %>',
dataType: 'jsonp',
type: 'PUT',
data: $('form').serialize(),
success: function(cart) {
$('#cart').fadeOut().html('');
cart.items.each(function(c,item) {
$('#cart').append('<li>'+item.manufacturer+' '+item.model+'</li>');
}
$('#cart').fadeIn();
}
});
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment