I’m trying to set up the Depot app from Agile Web D. and I
got this error after C1 - Creating a Cart.
The exact error looks like this:
NoMethodError in StoreController#add_to_cart
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
E:/InstantRails/rails_apps/depot/app/models/cart.rb:9:in add_product' E:/InstantRails/rails_apps/depot/app/controllers/store_controller.rb: 8:in
add_to_cart’
The contents of cart.rb:
class Cart
attr_reader :items
def initialize
@items = []
end
def add_product(product)
@itmes << product
debugger
end
end
The contents of store_controller.rb
class StoreController < ApplicationController
def index
@products = Product.find_products_for_sale
end
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
@cart.add_product(product)
debugger
end
private
def find_cart
session[:cart] ||=Cart.new
end
end
What could be the problem?