I''m trying to set up the Depot app from Agile Web Development and I got this error after C1 - Creating a Cart. The exact error looks like this: ------------------------------------------------------------------- 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.<< E:/InstantRails/rails_apps/depot/app/models/cart.rb:9:in `add_product'' E:/InstantRails/rails_apps/depot/app/controllers/store_controller.rb: 8:in `add_to_cart'' ------------------------------------------------------------------ The contents of cart.rb: --------------------------------------------- class Cart attr_reader :items def initialize @items = [] end def add_product(product) @itmes << product debugger end end -------------------------------------------------- The contents of store_controller.rb ------------------------------------------------------------------------------- class StoreController < ApplicationController def index @products = Product.find_products_for_sale end def add_to_cart @cart = find_cart product = Product.find(params[:id]) @cart.add_product(product) debugger end private def find_cart session[:cart] ||=Cart.new end end --------------------------------------------------------------------------------- What could be the problem? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 15, 3:06 pm, korre <corin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> def add_product(product) > @itmes << product > debuggerYou''ve typoed @items Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yup. That did the trick :) Ooops.. On Apr 15, 5:15 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 15, 3:06 pm, korre <corin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > def add_product(product) > > @itmes << product > > debugger > > You''ve typoed @items > > Fred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
- NoMethodError in Agile Web Devleopment Depot Tutorial
- NoMethodError in StoreController#add_to_cart -> getting nil
- NoMethodError in StoreController#add_to_cart
- Errors ... errors and errors.