Women in Technology

Hear us Roar



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.

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • "Showing recipes in a category" code
    2005-03-14 07:30:33  automat_svet [View]

    Curth,
    first of all thank you very much for the fast reply and really usefull article.
    I had no problem following your tutorial, the error message came out when I tried to implement the 'find_by' as suggested in the previous comments.
    I'm really new in all this and I'm just tring to learn different ways to do the same job.

    Cheers
    Automat_svet