| @@ -1,5 +1,7 @@ | |||||
| class CartsController < ApplicationController | class CartsController < ApplicationController | ||||
| before_action :set_cart, only: [:show, :edit, :update, :destroy] | before_action :set_cart, only: [:show, :edit, :update, :destroy] | ||||
| # QUESTION: How do we call this with call? | |||||
| rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart | |||||
| # GET /carts | # GET /carts | ||||
| # GET /carts.json | # GET /carts.json | ||||
| @@ -71,4 +73,9 @@ class CartsController < ApplicationController | |||||
| def cart_params | def cart_params | ||||
| params.fetch(:cart, {}) | params.fetch(:cart, {}) | ||||
| end | end | ||||
| def invalid_cart | |||||
| logger.error "Attempt to access invalid cart #{params[:id]}" | |||||
| redirect_to store_index_url, notice: 'Invalid cart' | |||||
| end | |||||
| end | end | ||||
| @@ -74,6 +74,6 @@ class LineItemsController < ApplicationController | |||||
| # Never trust parameters from the scary internet, only allow the white list through. | # Never trust parameters from the scary internet, only allow the white list through. | ||||
| def line_item_params | def line_item_params | ||||
| params.require(:line_item).permit(:product_id, :cart_id) | |||||
| params.require(:line_item).permit(:product_id) | |||||
| end | end | ||||
| end | end | ||||
| @@ -37,7 +37,8 @@ class LineItemsControllerTest < ActionDispatch::IntegrationTest | |||||
| end | end | ||||
| test "should update line_item" do | test "should update line_item" do | ||||
| patch line_item_url(@line_item), params: { line_item: { cart_id: @line_item.cart_id, product_id: @line_item.product_id } } | |||||
| patch line_item_url(@line_item), | |||||
| params: { line_item: { product_id: @line_item.product_id } } | |||||
| assert_redirected_to line_item_url(@line_item) | assert_redirected_to line_item_url(@line_item) | ||||
| end | end | ||||