Forum: Ruby on Rails 'depot' tutorial failing on adding to cart

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D937f79213452eeb2862078b0ce1b3c6?d=identicon&s=25 Steve Savery (Guest)
on 2006-04-18 13:02
(Received via mailing list)
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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-18 15:00
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.<<
> --
8716cce9a7b721786e5425b8cc1f9951?d=identicon&s=25 sean lynch (Guest)
on 2006-04-18 16:14
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:in `add_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 Francis 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.<<
>> --
This topic is locked and can not be replied to.