Manuel Manuel
2010-Jun-20 22:26 UTC
NoMethodError in StoreController#add_to_cart -> getting nil
Hey everybody, I am currently following the depot application from the book Web Agile Development with Rails (3rd Edition) but after creating the controller for the Store and the Cart model, I am always getting a nil product, no matter how many products I add to the database. I am very new with RoR (this only the page 110 of the book) and thus I am not very sure about what I could do to mitigate the problem. Thanks a lot in advance! -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Manuel Manuel
2010-Jun-20 22:39 UTC
Re: NoMethodError in StoreController#add_to_cart -> getting nil
Manuel Manuel wrote:> Hey everybody, > > I am currently following the depot application from the book Web Agile > Development with Rails (3rd Edition) but after creating the controller > for the Store and the Cart model, I am always getting a nil product, no > matter how many products I add to the database. > I am very new with RoR (this only the page 110 of the book) and thus I > am not very sure about what I could do to mitigate the problem. > > Thanks a lot in advance!The errors are both Cart.rb, line number 9: def add_product(product) -> @items << product end and def add_to_cart product = Product.find(params[:id]) @cart = find_cart -> @cart.add_product(product) end Error: 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.<< -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.