When following the ONrails "Rolling on Ruby with Rails" tutorial part1 I (already) encountered the first complication. After doing those basic actions to set up the basic site, the tutorial tells me to overwrite the "list" method included in the "scaffold :recipe" method which we find in the recipe controller with this code: def list @recipes = recipe.find_all end Now this code doesn''t work. When trying to view my site I keep getting an error message which says that the variable recipe is undefined. With the (average) knowledge I own concerning programming I suppose "@recipes" should define the variable, which doesn''t happen here. I searched half rubyonrails.org looking for another way of defining that variable, but it''s alway "@recipe". I followed every step in that tutorial closely, does anyone know what''s wrong? I use Ruby version 182-14. thx in advance -- Posted via http://www.ruby-forum.com/.
Hi, You don''t need to define variables in Ruby. The problem is likely to be the case of the class you''re calling. The line should read: @recipes = Recipe.find_all Hope that helps, Steve Simon wrote:> When following the ONrails "Rolling on Ruby with Rails" tutorial part1 I > (already) encountered the first complication. > > After doing those basic actions to set up the basic site, the tutorial > tells me to overwrite the "list" method included in the "scaffold > :recipe" method which we find in the recipe controller with this code: > > def list > @recipes = recipe.find_all > end > > Now this code doesn''t work. When trying to view my site I keep getting > an error message which says that the variable recipe is undefined. > With the (average) knowledge I own concerning programming I suppose > "@recipes" should define the variable, which doesn''t happen here. > > I searched half rubyonrails.org looking for another way of defining that > variable, but it''s alway "@recipe". I followed every step in that > tutorial closely, does anyone know what''s wrong? I use Ruby version > 182-14. > > > thx in advance >
On Thu, May 11, 2006 at 11:22:32AM +0200, Simon wrote:> When following the ONrails "Rolling on Ruby with Rails" tutorial part1 I > (already) encountered the first complication. > > After doing those basic actions to set up the basic site, the tutorial > tells me to overwrite the "list" method included in the "scaffold > :recipe" method which we find in the recipe controller with this code: > > def list > @recipes = recipe.find_all > end > > Now this code doesn''t work. When trying to view my site I keep getting > an error message which says that the variable recipe is undefined. > With the (average) knowledge I own concerning programming I suppose > "@recipes" should define the variable, which doesn''t happen here.I suspect that you want Recipe.find_all, not recipe.find_all. - Matt
Good to know the reason why. Ruby has a naming convention where Recipe refers to a class and recipe is a local variable, that holds a reference to an instance of an object .find_all is a method of a Class. You don''t need an instance of an object to reference class methods just the class definition (I know in Ruby this is not strictly correct because Everything in Ruby is an object even a Class) So for example Recipe.new or Recipe.find_all are methods of the Class my_recipe.ingredients is a method on an object referenced by the local variable my_recipe (which from the name is probably an instance of Recipe). It could just as easily be @my_recipe.ingredients HTH Ross> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org]On Behalf Of Stephen > Bartholomew > Sent: Thursday, 11 May 2006 7:47 PM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] undefined?? > > > Hi, > > You don''t need to define variables in Ruby. > > The problem is likely to be the case of the class you''re > calling. The > line should read: > > @recipes = Recipe.find_all > > Hope that helps, > > Steve > > > Simon wrote: > > When following the ONrails "Rolling on Ruby with Rails" > tutorial part1 I > > (already) encountered the first complication. > > > > After doing those basic actions to set up the basic site, > the tutorial > > tells me to overwrite the "list" method included in the "scaffold > > :recipe" method which we find in the recipe controller with > this code: > > > > def list > > @recipes = recipe.find_all > > end > > > > Now this code doesn''t work. When trying to view my site I > keep getting > > an error message which says that the variable recipe is undefined. > > With the (average) knowledge I own concerning programming I suppose > > "@recipes" should define the variable, which doesn''t happen here. > > > > I searched half rubyonrails.org looking for another way of > defining that > > variable, but it''s alway "@recipe". I followed every step in that > > tutorial closely, does anyone know what''s wrong? I use Ruby version > > 182-14. > > > > > > thx in advance > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >