small medium large xlarge

Generic-user-small
01 Jun 2014, 11:38
Xanothos (2 posts)

In the PDF in Ch9.D3 we have the following snippet:

def create
  @line_item = @cart.line_items.build(product: product)
  product = Product.find(params[:product_id])

  respond_to do |format|
    if @line_item.save
      format.html { redirect_to @line_item.cart, notice: 'Line item was successfully created.'}
      format.json { render action: 'show', status: :created, location: @line_item}
    else
      ...
    end
  end
end

Any thoughts on why the authors chose to redirect to @line_item.cart as opposed to simply using the existing @cart instance?

Doing an assert_same on @line_item.cart and @cart proves that they are the same object.

You must be logged in to comment