Women in Technology

Hear us Roar



Article:
  Rolling with Ruby on Rails
Subject:   Errors in the end
Date:   2005-07-27 12:09:43
From:   acidbox
Response to: Errors in the end

I am also getting a similar error:


RuntimeError in Recipe#edit


Showing /recipe/edit.rhtml where line #20 raised:


Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id


Extracted source (around line #20):


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


23:



Does anyone know what this is or how I can fix it? I thought I had triple-checked my code.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Errors in the end
    2005-07-27 12:35:22  acidbox [View]

    Fixed the problem.

    Basically I had to change this:

    <%= ' selected' if category.id == @recipe.category.id %>

    to this:

    <%= ' selected' if category.id == @recipe.category_id %>

  • Curt Hibbs photo Errors in the end
    2005-07-27 12:32:34  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

    Check your database and make sure all of your recipe entries have valid category ids.