small medium large xlarge

Generic-user-small
03 Feb 2012, 09:48
Kay L. (2 posts)

I’m working to the book and it has been a great experience so far! Just now I ran into the following error and I can’t seem to solve it:

depot/app/models/cart.rb:6: syntax error, unexpected keyword_end, expecting $end

Trace:

app/controllers/application_controller.rb:7:in `current_cart'
app/controllers/line_items_controller.rb:43:in `create'

File the bad stuff happens:

class ApplicationController < ActionController::Base
  protect_from_forgery

  private

    def current_cart
      Cart.find(session[:cart_id])
    rescue ActiveRecord::RecordNotFound
      cart = Cart.create
      session[:cart_id] = cart.id
      cart
    end
end

From what I understand something goes wrong in ending the function/file. I just cannot seem to figure out what is wrong with the code, I’ve already tried to download the file of your website but that doesn’t seem to solve the problem either.

I hope someone can help me solve the error and understand it better. Thanks.

Generic-user-small
03 Feb 2012, 20:54
farout (5 posts)

Kay,

The end error is in cart.rb, probably the add_product method:

  def add_product(product_id)
    current_item = line_items.find_by_product_id(product_id)
    
    if current_item
       current_item.quantity += 1
    else
      current_item = line_items.build(product_id: product_id)
    end    
    current_item
  end
Generic-user-small
04 Feb 2012, 07:50
Kay L. (2 posts)

You are completely right, thanks a lot. I don’t know where I was with my head that I didn’t see this.

You must be logged in to comment