![]() | Pg 111: Error regarding StoreController #add_to_cart |
|
03 Aug 2008, 01:32
Max Norman (17 posts) |
When I try to add something to my cart, I get this error: You have a nil object when you didn’t expect it! app/models/cart.rb:9:in `add_product’ — What exactly is the problem? |
|
03 Aug 2008, 03:10
Sam Ruby (549 posts) |
Make sure that cart.rb looks exactly like this href=”http://media.pragprog.com/titles/rails3/code/depot_f/app/models/cart.rb”>http://media.pragprog.com/titles/rails3/code/de… Line 9 is @items << product The message indicates that @items = [] Check both lines, for spelling mistakes, missing @ signs or the like. |
|
03 Aug 2008, 03:16
Max Norman (17 posts) |
Thank you for responding, Mr. Ruby. It is very comforting as a reader to know that you are so available and outgoing. I can’t find and errors with my cart.rb. I’ve pasted it up here:
|
|
03 Aug 2008, 11:36
Sam Ruby (549 posts) |
That code appears to be correct. My next guess is that somehow you created a Cart without setting @items correctly, and then subsequently fixed the code, but the original Cart is still captured and stored in your session. Try rake db:sessions:clear |
|
03 Aug 2008, 16:53
Max Norman (17 posts) |
It worked! Thank you! |
|
03 Dec 2008, 14:19
Michael Tobola (2 posts) |
Hi, |
| You must be logged in to comment |

