'depot' tutorial failing on adding to cart

Hi

I’m very keen to learn RoR and have been following the Agile Web
Development with Rails book (first edition). However, I’ve come
across a problem which has had me stumped for days now.

After following the instructions up to page 85 I have tried testing
the code thus far, as suggested, by adding an item to the cart. But I
am getting the following error:


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 occured while evaluating nil.<<

I’ve been testing in Firefox to ensure that the cookie is being
created (it appears to be OK). Does anyone know what I’m missing/
doing wrong? Also, this may or may not help… if I try to start the
lighttpd server I get nothing working and have to resort to using
Webrick. So it may be a installation fault and not a coding error.

Thanks in advance,

Steve

Hi Steve,

can you post the contents of your add_to_cart method and the rest of the
stack trace?

Alan

Steve Savery wrote:


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 occured while evaluating nil.<<

Steve,

Could you also post your cart.rb, especially the add_product:

Full Trace
#{RAILS_ROOT}/app/models/Cart.rb:12:in add_product' #{RAILS_ROOT}/app/controllers/store_controller.rb:10:inadd_to_cart’

I also want to see how your attribute reader is set up in cart.rb, as
this is not a normal generated model.

-Sean

Alan F. wrote:

Hi Steve,

can you post the contents of your add_to_cart method and the rest of the
stack trace?

Alan

Steve Savery wrote:


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 occured while evaluating nil.<<