Women in Technology

Hear us Roar



Article:
  Rolling with Ruby on Rails
Subject:   Action Control:Exception caught
Date:   2006-03-30 07:53:04
From:   doori
I am a new Ruby User and started working with it previously. As I tried to finish the first tutorial I caught this exception:
You have a nil object when you didn't expect it!


The error occured while evaluating nil.name
...on line #18:
<td><%= recipe.category.name %></td>


I had a look at the previous posts, but didn't find a suitable solution.
Did anyone have the same error and can help me to figure it out?


thx!

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Curt Hibbs photo Action Control:Exception caught
    2006-03-30 07:58:35  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

    The recipe you are trying to display probably does not have a category assigned to it -- check your database. If the category_id field is null, then "recipe.category" will return the value "nil" instead of a category object, and since the "nil" object doesn't have a "name" method, you get this error.