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.