# 'depot' tutorial failing on adding to cart

**URL:** <https://www.ruby-forum.com/t/depot-tutorial-failing-on-adding-to-cart/58094>\
**Category:** Rails\
**Created:** [April 18, 2006, 1:02pm UTC](https://www.ruby-forum.com/t/depot-tutorial-failing-on-adding-to-cart/58094 "2006-04-18T13:02:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Savery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@Steve\_Savery](https://www.ruby-forum.com/u/Steve_Savery)\
**Post date:** [April 18, 2006, 1:02pm UTC](https://www.ruby-forum.com/t/depot-tutorial-failing-on-adding-to-cart/58094/1 "2006-04-18T13:02:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Savery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@Steve\_Savery](https://www.ruby-forum.com/u/Steve_Savery)\
**Post date:** [April 18, 2006, 3:00pm UTC](https://www.ruby-forum.com/t/depot-tutorial-failing-on-adding-to-cart/58094/2 "2006-04-18T15:00:39Z")

</div>

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.\<\<

---

<div class="post-metadata">

**Author:** ![Steve\_Savery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@Steve\_Savery](https://www.ruby-forum.com/u/Steve_Savery)\
**Post date:** [April 18, 2006, 4:14pm UTC](https://www.ruby-forum.com/t/depot-tutorial-failing-on-adding-to-cart/58094/3 "2006-04-18T16:14:35Z")

</div>

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 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.\<\<
