ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Rolling with Ruby on Rails, Part 2
Subject:   "Showing recipes in a category" code
Date:   2005-03-11 16:57:37
From:   curth
Response to: "Showing recipes in a category" code

First of all, let me say that what I answered above about using @category_id is incorrect, the article is correct as written (I must have been on drugs when I wrote that :-).


In you case, I'm assuming that you cut'n'paste the code for list.rhtml, so the line on which you are getting the error contains "@recipes.each", which is going to iterate through each member of the collection contained in @recipes.


The error says the @recipes contains the value "nil" (the Ruby equivalent of Java's null), and that the object "nil" does not have a method named "each".


That means that something is wrong in the controller where @recipes is being assigned its value. Make sure you list method looks like this:



def list
@category = @params['category']
@recipes = Recipe.find_all
end


If it already does, then that means that find_all is failing to find any recipes in the database (or failing to find the database).


Did you go through part 1 successfully? Does your database contain some recipes?


You could try starting off the my zip file for your code and use my sql file to initialize your database, and then start working through part 2.


1 to 1 of 1
1 to 1 of 1