bradwrage-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Apr-04 06:43 UTC
NoMethodError in PublicController
Hello, I''m following a tutorial with a public controller, line_item model, and cart model. When I try to add an item to the cart I am getting an error NoMethodError in PublicController#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.<< Here is my code http://pastie.org/436638 Thanks --~--~---------~--~----~------------~-------~--~----~ 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 4, 7:43 am, "bradwr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <bradwr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > I''m following a tutorial with a public controller, line_item model, > and cart model. When I try to add an item to the cart I am getting an > error > > NoMethodError in PublicController#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.<< >On the face of it this doesn''t make sense - the only thing you call << on is @items and that is initialized to [] in the Cart''s initialize method. My guess would be that this was missing in your first attempt and although you have now fixed this, the session still contains a bad object with nil @items. Restarting the browser would fix it if this was the problem (as well as outlining one of the pitfalls with storing complex objects in the session). Fred> Here is my code > > http://pastie.org/436638 > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bradwrage-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Apr-04 17:27 UTC
Re: NoMethodError in PublicController
Thanks for the reply. Restarting the browser did help, however another one arose which is the sessions. I''m following the lynda ruby on rails essentials which is an older version of rails. No where in the tutorial did they go into detail about sessions, so I assume it''s more complicated with my newer version. Any suggestions as to what I should do next? Scrap the lynda tutorial and do another? I also haven''t upgrade to the newest rails version. Brad On Apr 4, 3:42 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 4, 7:43 am, "bradwr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <bradwr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > I''m following a tutorial with a public controller, line_item model, > > and cart model. When I try to add an item to the cart I am getting an > > error > > > NoMethodError in PublicController#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.<< > > On the face of it this doesn''t make sense - the only thing you call << > on is @items and that is initialized to [] in the Cart''s initialize > method. My guess would be that this was missing in your first attempt > and although you have now fixed this, the session still contains a bad > object with nil @items. Restarting the browser would fix it if this > was the problem (as well as outlining one of the pitfalls with storing > complex objects in the session). > > Fred > > > Here is my code > > >http://pastie.org/436638 > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---