small medium large xlarge

Mittelalter_002_pragsmall
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): bq.app/controllers/store_controller.rb:11:in `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
    end

    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}
        end 

[...]

private 
    def find_cart
        $cart = session[:cart] ||= Cart.new 
    end

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

Mittelalter_002_pragsmall
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