Remove Product From Cart

Remove Product From Cart

Step1-add this link into index.html.erb-carts
<%= link_to "Remove",  remove_cart_path(cart_item.product.id), data: {method: :delete, remote: true}  %>

Step2-Create a new method in product controller.rb
 def remove_cart
    @product = Product.friendly.find(params[:id])
    @remove_cart = current_cart.cart_items.where(product_id: @product.id).first.destroy
    redirect_to "/carts"

  end
Step3-Create a Routes path
delete 'remove_cart_item/:id' => "products#remove_cart", as: :remove_cart

Comments

Popular posts from this blog

Check Your ageInDays by Javascript