Rolling with Ruby on Rails, Part 2
Subject:   Error?
Date:   2005-05-13 21:31:07
From:   boboroshi
Utilizing your new code download (which works) and following the first two steps, i run into this error after the category application:

NoMethodError in Recipe#new

Showing /recipe/new.rhtml where line #19 raised:

undefined method `each' for nil:NilClass
Extracted source (around line #19):


17: Category:<br/>
18: <select name="recipe[category_id]">
19: <% @categories.each do |category| %>
20: <option value="<%= %>">
21: <%= %>
22: </option>

Full Threads Newest First

Showing messages 1 through 3 of 3.

  • Error?
    2005-06-04 16:21:57  Meindert [View]

    Add this method to the class RecipeController:

    def initialize
    @categories = Category.find_all

    From now on @categories will be defined when new.rhtml comes up.
  • Error?
    2005-06-24 08:03:43  tjmcgee [View]

    I get the same error, have you found any resolution?
  • Error?
    2007-01-27 16:02:59  endalk [View]

    make sure any of your category in your list is not NULL i.e. In the database cookbook, browse the table recipe and make sure none of the category_id field is not NULL.