small medium large xlarge

Drp_pragsmall
13 Aug 2008, 19:55
Dan Pendergrass (11 posts)

Iteration D3 went fine, but upon making changes to hide the cart when empty I ran into an error that posts in the log.

Processing StoreController#add_to_cart (for 127.0.0.1 at 2008-08-13 12:28:16) [POST] Session ID: 463af3a2fe1e675f4c854eed5b92c1d1 Parameters: {“commit”=>”Add to Cart”, “authenticity_token”=>”de083c44dd5d4f7974dc8b4e6f2d2ec4d21c95e3”, “action”=>”add_to_cart”, “id”=>”3”, “controller”=>”store”} Product Columns (0.000000) SHOW FIELDS FROM products Product Load (0.016000) SELECT * FROM products WHERE (products.id = 3) 

NoMethodError (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.«): /app/models/cart.rb:22:in `add_product’

Maybe I’ve looked at this too long, because I’ve gone over it with a fine tooth comb to no avail.

Here’s the code from my cart method.

def add_product(product) current_item =@items.find {|item| item.product == product}

if current_item
  current_item.increment_quantity
else
  current_item << CartItem.new(product)
  @items << current_item
end
current_item   end

Suggestions appreciated.

Thanks

Drp_pragsmall
13 Aug 2008, 20:38
Dan Pendergrass (11 posts)

After some changes I’m now getting this.

Processing StoreController#add_to_cart (for 127.0.0.1 at 2008-08-13 13:32:33) [POST] Session ID: 463af3a2fe1e675f4c854eed5b92c1d1 Parameters: {“commit”=>”Add to Cart”, “authenticity_token”=>”de083c44dd5d4f7974dc8b4e6f2d2ec4d21c95e3”, “action”=>”add_to_cart”, “id”=>”3”, “controller”=>”store”} Attempt to access invalid product 3 Redirected to http://localhost:3000/store Completed in 0.09400 (10 reqs/sec) | DB: 0.03100 (32%) | 302 Found [http://localhost/store/add_to_cart/3]

Processing StoreController#index (for 127.0.0.1 at 2008-08-13 13:32:33) [GET] Session ID: 463af3a2fe1e675f4c854eed5b92c1d1 Parameters: {“action”=>”index”, “controller”=>”store”} Product Load (0.000000) SELECT * FROM products ORDER BY title Rendering template within layouts/store Rendering store/index Product Columns (0.016000) SHOW FIELDS FROM products Rendered store/_cart (0.00000) Completed in 0.01600 (62 reqs/sec) | Rendering: 0.00000 (0%) | DB: 0.06300 (393%) | 200 OK [http://localhost/store]

It seems to think everything worked fine, but the sidebar is empty (sigh).

You must be logged in to comment