Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
Created June 12, 2014 22:02
Show Gist options
  • Save rocodev-tech/069e4e06a5018a1b91c7 to your computer and use it in GitHub Desktop.
Save rocodev-tech/069e4e06a5018a1b91c7 to your computer and use it in GitHub Desktop.
app/controllers/products_controller.rb
def add_to_cart
@product = Product.find(params[:id])
if !current_cart.items.include?(@product)
current_cart.add_product_to_cart(@product)
flash[:notice] = "你已成功將 #{@product.title} 加入購物車"
else
flash[:warning] = "你的購物車內已有此物品"
end
redirect_to :back
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment