small medium large xlarge

12 Mar 2009, 18:43
Philipp Ringli (6 posts)

I am stuck on page 178 with the following problem:

bq.NoMethodError (You have a nil object when you didn’t expect it! bq.The error occurred while evaluating nil.add_product): `add_to_cart’

Obviously the before_filter isn’t doing what it’s supposed to do?

class StoreController < ApplicationController

    before_filter :find_cart, :except => :empty_cart

    def index
        @products = Product.find_products_for_sale

    def add_to_cart
        product = Product.find(params[:id])        
        @current_item = @cart.add_product(product)

        respond_to do |format| 
            format.js if request.xhr? 
            format.html {redirect_to_index}


    def find_cart
        $cart = session[:cart] ||= 

It worked, before I removed the redundant calls to find_cart.

12 Mar 2009, 18:51
Philipp Ringli (6 posts)

Ouch… since I cannot delete this post, let it be a shining example of the malicious PHP BUG.

Avatar quadrado_pragsmall
20 Oct 2017, 12:39
Andre Chaves (6 posts)

Shining example it is… not something that wouldn´t be expected from php :)

You must be logged in to comment