Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Created August 11, 2008 01:11
Show Gist options
  • Save patrickberkeley/4794 to your computer and use it in GitHub Desktop.
Save patrickberkeley/4794 to your computer and use it in GitHub Desktop.
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
quantity = params[:quantity]
quantity ||= 1
if quantity.to_i > product.quantity.to_i
logger.info "This product only has #{product.quantity.to_i} remaining."
render :nothing => true, :status => 400 and return
else
@cart.add_product(product, quantity.to_i)
show_cart and return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment