抄Aglie Web Develepment with Rails,second Edition样例出错

问题:
    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.<<

RAILS_ROOT: ./script/../config/..

Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/models/cart.rb:7:in `add_product'
#{RAILS_ROOT}/app/controllers/store_controller.rb:10:in `add_to_cart'

Cart.rb

class Cart
  attr_reader :items
  def lnitialize
    @items=[]
  end
  def add_product(product)
    @items << product
  end
end

store_controller.rb
        class StoreController < ApplicationController

  def index
    @products = Product.find_products_for_sale
    @time=Time.now
  end
  def add_to_cart
      @cart = find_cart
      product=Product.find( params[:id] )
      @cart.add_product(product)           
    end
    
  private
  
  def find_cart
    unless session[:cart]
    session[:cart]= Cart.new
    end
    session[:cart]
  end
end
 谢谢 Rails 1.2.3
  

你可能感兴趣的:(Web,Rails,idea)