small medium large xlarge

Generic-user-small
23 Apr 2009, 16:14
FRANK CHEUNG (1 post)

Working through the Agile Web Development w/ Rails book on p114. I can add single items of each to the cart but when I try to add a second item I get 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 occurred while evaluating nil.+

Any idea why this is happening? Thanks.

Frank.

Generic-user-small
14 Jul 2010, 22:12
Sean Luckett (3 posts)

Well, over a year later and someone else has the same problem. An application trace shows this:

depot/app/models/cart_item.rb:11:in increment_quantity' depot/app/models/cart.rb:15:in add_product’ depot/app/controllers/store_controller.rb:10:in add_to_cart' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:1331:in send’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:1331:in perform_action_without_filters' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/filters.rb:617:in call_filters’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/filters.rb:610:in perform_action_without_benchmark' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue’ /var/lib/gems/1.8/gems/activesupport-2.3.6/lib/active_support/core_ext/benchmark.rb:17:in ms' /var/lib/gems/1.8/gems/activesupport-2.3.6/lib/active_support/core_ext/benchmark.rb:17:in ms’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/rescue.rb:160:in perform_action_without_flash’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/flash.rb:151:in perform_action' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:532:in send’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:532:in process_without_filters' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/filters.rb:606:in process’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:391:in process' /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/base.rb:386:in call’ /var/lib/gems/1.8/gems/actionpack-2.3.6/lib/action_controller/routing/route_set.rb:438:in `call’

I tried to ignore it and go on with the book. However, I want to solve the problem so I can continue to follow along with coding. Thanks for any help.

Sean

Generic-user-small
14 Jul 2010, 22:19
Sean Luckett (3 posts)

Never mind. Coder Error – duplicate methods. Wish I’d seen that before I went and shot off my big keyboard.

You must be logged in to comment