Hi, I am doing book examples while reading Agile Web Development with Rails. I am stuck at chapter 8 Task C: Cart Creation at page 82. I am always getting errors when add to cart or display to cart. The error is: NoMethodError in Store#add_to_cart WARNING: You have a nil object when you probably didn''t expect it! Odds are you want an instance of Array instead. Look in the callstack to see where you''re working with an object that could be nil. Investigate your methods and make sure the object is what you expect! /app/models/Cart.rb:21:in `add_product'' /app/controllers/store_controller.rb:16:in `add_to_cart'' script/server:49 I also downloaded the sample code from pragmatic programmer web site, but depot8 gets error as well, it is different one though: NoMethodError in Store#add_to_cart undefined method `<<'' for nil:NilClass /app/models/cart.rb:21:in `add_product'' D:/BookCode/rails-code/depot8/app/controllers/store_controller.rb:16:in `add_to_cart'' script/server:51 Has anyone successfully finished this task? Can anyone help me? Thanks. Ming
Cristiano Dias
2005-Aug-04 16:08 UTC
Re: problems with examples in Agile Web Development with Rails
All sample code worked fine for me. This error message does not give much detail, but you can always download the whole source code from the book website. I am merely guessing, but maybe you just pasted code in the wrong part of a class... On 8/4/05, Ming Ma <mingworld-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am doing book examples while reading Agile Web Development with > Rails. I am stuck at chapter 8 Task C: Cart Creation at page 82. > > I am always getting errors when add to cart or display to cart. The error is: > > NoMethodError in Store#add_to_cart > WARNING: You have a nil object when you probably didn''t expect it! > Odds are you want an instance of Array instead. > > Look in the callstack to see where you''re working with an object that > could be nil. > Investigate your methods and make sure the object is what you expect! > /app/models/Cart.rb:21:in `add_product'' > /app/controllers/store_controller.rb:16:in `add_to_cart'' > script/server:49 > > I also downloaded the sample code from pragmatic programmer web site, > but depot8 gets error as well, it is different one though: > > NoMethodError in Store#add_to_cart > undefined method `<<'' for nil:NilClass > /app/models/cart.rb:21:in `add_product'' > D:/BookCode/rails-code/depot8/app/controllers/store_controller.rb:16:in > `add_to_cart'' > script/server:51 > > Has anyone successfully finished this task? Can anyone help me? > > > > Thanks. > > > > Ming > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >