Hello, Still vastly enjoying learning Rails, albeit slowly. I''m up to the point now where they have you build the cart and add an item in, where the display page shows the number of items in the cart. After entering all the code, I got an error and I am kind of stuck on how to debug it. I checked all the usual suspects of spelling errors, missing braces, etc. Since I only know the rudiments of Ruby, I''m bogged down on where to go next.... here is what I am seeing: --------------------------------------------------------------------------------- NoMethodError in Store#display_cart Showing /store/display_cart.rhtml where line #10 raised: 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! Extracted source (around line #10): 7: 8: <body> 9: <h1>Display Cart</h1> 10: <p>Your cart contains <%= @items.size %> items.</p> 11: 12: </body> 13: </html> --------------------------------------------------------------------------------- Also, I''m wondering at what point I need to really understand Ruby to continue with this. I''ve read throught the appendix on Ruby already, and I understand most of that, but it''s just an introduction. I understand the basics of OO programming, having been previously exposed to it (although I am not an engineer, I''m a front end guy - but I have taken a one week Java course, done self study etc, so I understand it to a point). One thing that is throwing me a bit is symbols. I seem to want to liken it to "this" in JavaScript, which I don''t think is quite right. Also, the syntax => is throwing me... is this the same as dot syntax? How should I read that? Thanks Tom http://www.pixelmech.com/
Tom, I would highly suggest to get "Pickaxe" (nickname of the "Programming Ruby" book). There is a second edition that you have to buy but edition one is for free. http://www.pragmaticprogrammer.com/titles/ruby/index.html (for money) http://www.ruby-doc.org/docs/ProgrammingRuby (for nada) also you get a lot of help here: http://www.ruby-doc.org http://www.rubyonrails.org http://api.rubyonrails.com Before understanding more of Ruby you will not have the amount of fun that Rails is supposed to be. However, Pickaxe, even though challenging sometimes, is great to read. enjoy! Peter On Mon, 07 Nov 2005 14:13:28 +0100, Tom Dell''Aringa <pixelmech-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > Still vastly enjoying learning Rails, albeit slowly. I''m up to the point > now where they have you > build the cart and add an item in, where the display page shows the > number of items in the cart. > After entering all the code, I got an error and I am kind of stuck on > how to debug it. I checked > all the usual suspects of spelling errors, missing braces, etc. Since I > only know the rudiments of > Ruby, I''m bogged down on where to go next.... here is what I am seeing: > > --------------------------------------------------------------------------------- > NoMethodError in Store#display_cart > > Showing /store/display_cart.rhtml where line #10 raised: > > 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! > > Extracted source (around line #10): > > 7: > 8: <body> > 9: <h1>Display Cart</h1> > 10: <p>Your cart contains <%= @items.size %> items.</p> > 11: > 12: </body> > 13: </html> > --------------------------------------------------------------------------------- > > Also, I''m wondering at what point I need to really understand Ruby to > continue with this. I''ve > read throught the appendix on Ruby already, and I understand most of > that, but it''s just an > introduction. I understand the basics of OO programming, having been > previously exposed to it > (although I am not an engineer, I''m a front end guy - but I have taken a > one week Java course, > done self study etc, so I understand it to a point). > > One thing that is throwing me a bit is symbols. I seem to want to liken > it to "this" in > JavaScript, which I don''t think is quite right. Also, the syntax > > => > > is throwing me... is this the same as dot syntax? How should I read that? > > Thanks > > Tom > > > > > http://www.pixelmech.com/ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Tom Dell''Aringa
2005-Nov-07 16:33 UTC
Re: NoMethodError in my cart - how do I debug this?
--- Pete <pertl-BA+cFGlbTmA@public.gmane.org> wrote:> I would highly suggest to get "Pickaxe" (nickname of the "Programming > Ruby" book)...<snip> > Before understanding more of Ruby you will not have the amount of fun that > Rails is supposed to be. However, Pickaxe, even though challenging sometimes, is > great to read.I had planned on getting the Pickaxe book at some point. Are you suggesting I am pretty much at the point now where I should get more up to speed on Ruby before I continue with Rails? If anyone else has any suggestions about the error - pasted below (following rails book). Thanks Tom> On Mon, 07 Nov 2005 14:13:28 +0100, Tom Dell''Aringa <pixelmech-/E1597aS9LQ@public.gmane.orgm> > wrote: > > --------------------------------------------------------------------------------- > > NoMethodError in Store#display_cart > > > > Showing /store/display_cart.rhtml where line #10 raised: > > > > 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! > > > > Extracted source (around line #10): > > > > 7: > > 8: <body> > > 9: <h1>Display Cart</h1> > > 10: <p>Your cart contains <%= @items.size %> items.</p> > > 11: > > 12: </body> > > 13: </html> > > ---------------------------------------------------------------------------------http://www.pixelmech.com/
> > I would highly suggest to get "Pickaxe" (nickname of the "Programming > > Ruby" book)...<snip>Seconded, along with Agile Web Development with Rails. No matter what stage you are in learning ruby and rails, both of these books are invaluable. As for your specific problem, I'd guess that the display_cart method in your store controller never sets the @items class variable.> One thing that is throwing me a bit is symbols. I seem to want to liken it to "this" in > JavaScript, which I don't think is quite right.No, it's not quite right! A symbol is a lightweight way to represent the names of things in ruby. The pickaxe has a better description ;) Tom Ward -- email : tom at popdog.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Tom Dell''Aringa
2005-Nov-07 18:08 UTC
Re: NoMethodError in my cart - how do I debug this?
--- Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote:> > > I would highly suggest to get "Pickaxe" (nickname of the "Programming > > > Ruby" book)...<snip> > > Seconded, along with Agile Web Development with Rails. No matter what > stage you are in learning ruby and rails, both of these books are > invaluable.I''m actually running through the Agile Rails book, which is where my error comes from. I''m reading the free 1st edition version right now - how much do the two editions differ? Tom http://www.pixelmech.com/
> I'm actually running through the Agile Rails book, which is where my error comes from. I'm reading > the free 1st edition version right now - how much do the two editions differ?I had no idea there was a free edition so I couldn't really say. Tom _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Tom Dell''Aringa
2005-Nov-07 23:46 UTC
Re: NoMethodError in my cart - how do I debug this?
--- Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote:> As for your specific problem, I''d guess that the display_cart method > in your store controller never sets the @items class variable.But I think it does... I have this in store_controller.rb: def display_cart @cart = find_cart @items = @cart_items end How accurate are the errors Ruby throws? I notice the error at the top states: "NoMethodError in Store#display_cart" I assume Store is the controller, if I look in the method above, is @cart_items supposed to be defined somewhere? Or is that instance variable just being declared there, I''m slightly confused. In any event, I do not have any cart_items method defined - could that be the no method error? Tom http://www.pixelmech.com/