Last active
December 15, 2015 13:29
-
-
Save andyh/5267931 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class ApplicationController... | |
| def clear_cart | |
| @cart.destroy | |
| session[:cart_id] = nil | |
| end | |
| end |
This file contains hidden or 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
| class CartController < ApplicationController | |
| def destroy | |
| @cart = current_cart | |
| clear_cart | |
| respond_to do |format| | |
| format.html { redirect_to root_url, notice: 'Your cart is currently empry' } | |
| format.json { head :no_content } | |
| end | |
| end | |
| end |
This file contains hidden or 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
| class LineItemsController < ApplicationController | |
| # DELETE /line_items/1 | |
| # DELETE /line_items/1.json | |
| def destroy | |
| @cart = current_cart | |
| @line_item = @cart.remove_product(params[:id]) | |
| respond_to do |format| | |
| if @line_item.save | |
| @line_item.destroy if @line_item.quantity == 0 | |
| if @cart.line_items.count.zero? | |
| clear_cart | |
| redirect_to root_url and return | |
| end | |
| format.html { redirect_to @cart, notice: 'Line item was successfully removed' } | |
| format.json { head :no_content } | |
| else | |
| format.html { render action: "new" } | |
| format.json { render json: @line_item.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment