Created
July 14, 2011 19:20
-
-
Save ogredude/1083212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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