small medium large xlarge

Generic-user-small
27 Sep 2011, 01:16
Javier Q (7 posts)

Hello,

I’ve been reading the lastes 2 editions (3 and 4) and I tested the first one months ago and I had some problems that I don’t remember but now I’m starting again with the depot application and I’m stuck in Task D: Cart creation after doing everything it appears a message of error

NameError in LineItemsController#create

undefined local variable or method `cart_id’ for #

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

What I have in application_controller is

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

and in line_items_controller :

def create @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.line_items.build(:product => product) #@line_item = LineItem.new(params[:line_item])

respond_to do |format|
  if @line_item.save
    format.html { redirect_to(@line_item.cart, :notice => 'Line item was successfully created.') }
    format.json { render :json => @line_item, :status => :created, :location => @line_item }
  else
    format.html { render :action => "new" }
    format.json { render :json => @line_item.errors, :status => :unprocessable_entity }
  end
end   end

It seems to be ok but it doesn’t work

Hope somebody can help

Thanks

Dave_gnome_head_isolated_pragsmall
27 Sep 2011, 02:03
Dave Thomas (390 posts)

You’re missing a colon—line 7 should be

Cart.find(session[:cart_id])
You must be logged in to comment