Skip to content

Instantly share code, notes, and snippets.

@ogredude
Created July 14, 2011 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ogredude/1083212 to your computer and use it in GitHub Desktop.
Save ogredude/1083212 to your computer and use it in GitHub Desktop.
def update_store_cart
store = Store.find(params[:store_id])
params[:item_ids] ||= []
params[:item_ids].each do |i|
Cart.add(current_user.id, i)
end
current_user.items.each do |i|
Cart.drop(current_user.id, i.id) unless params[:item_ids].include?(i.id.to_s) || i.store != store
end
flash[:success] = "Your cart has been updated!"
respond_to do |format|
format.html {
redirect_to (store_path(params[:store_id]))
}
format.js
end
end
<script>
$(document).ready(function() {
$('input[type=checkbox]').change(function() {
$.ajax({
url: '<%= update_store_cart_path %>',
type: 'PUT',
data: $('form').serialize(),
success: function(cart, status, xhr) {
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment