Hi All, 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
Dave Thomas
2005-Aug-04 18:54 UTC
Re: Stuck with the example (Agile Web Development with Rails)
On Aug 4, 2005, at 7:48, Ming Ma wrote:> Hi All, > > > > 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. > > > > /app/models/Cart.rb:21:in `add_product'' > /app/controllers/store_controller.rb:16:in `add_to_cart'' > script/server:49 > >Sounds like you don''t have a cart in your session. are cookies disabled on your browser? If not, try adding some debugging to see what Rails has in the session. Dave _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Ming Ma
2005-Aug-05 07:49 UTC
RE: Stuck with the example (Agile Web Development with Rails)
Thanks for your help. I turned off the computer with frustration last night. And I tried running the example this morning, and everything is fine without touching anything. (This time I tried with IE first instead of fire fox, it works fine with both browsers now). It is very odd that rebooting computer helped. Ming _____ From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Dave Thomas Sent: Friday, 5 August 2005 4:54 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Stuck with the example (Agile Web Development with Rails) On Aug 4, 2005, at 7:48, Ming Ma wrote: Hi All, 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. /app/models/Cart.rb:21:in `add_product'' /app/controllers/store_controller.rb:16:in `add_to_cart'' script/server:49 Sounds like you don''t have a cart in your session. are cookies disabled on your browser? If not, try adding some debugging to see what Rails has in the session. Dave _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails