Topic: NoMethodError in Admin#index , undefined method `name' for nil:NilClas

I am getting 'NoMethodError'

Please suggest on how to resolve this issue
Thanks a lot,


NoMethodError in Admin#index
.....
.....
undefined method `name' for nil:NilClass
.....
.....
Extracted source (around line #23):

20:     <% for reservation in reservations %>
21:           <tr class="<%= cycle('list_line_odd', 'list_line_even') %> ">
22:         <td class="list_description">
23:             <dt><%= link_to reservation.machine.name, reservation.machine %></dt>
24:         </td>
25:         <td> <%= reservation.startdate.strftime("%m/%d/%Y %I:%M %p")  %> </td>
26:         <td> <%= reservation.enddate.strftime("%m/%d/%Y %I:%M %p")  %> </td>

Last edited by bobsclrd (2012-10-26 02:48:42)

Re: NoMethodError in Admin#index , undefined method `name' for nil:NilClas

the stack trace tells you exactly what the problem is:

reservation.machine.name is nil.

what means that you are calling the 'name' method on 'nil' object, i.e.reservation.machine is NIL.