I’m having a real problem with nil objects in a view I’m playing with.
if I type …
<%= debug lesson.lesson_register.attendees %>
I get the following displayed in the browser …
- !ruby/object:Attendee
attributes:
enrollee_id: "25"
created_at: 2009-08-27 15:10:41
updated_at: 2009-08-27 15:10:41
id: "1"
attended: f
lesson_register_id: "1"
attributes_cache: {}
- !ruby/object:Attendee
attributes:
enrollee_id: "26"
created_at: 2009-08-27 15:10:41
updated_at: 2009-08-27 15:10:41
id: "2"
attended: t
lesson_register_id: "1"
attributes_cache: {}
if I type …
<%= debug lesson.lesson_register.attendees[0] %>
I get correctly …
--- !ruby/object:Attendee
attributes:
enrollee_id: "25"
created_at: 2009-08-27 15:10:41
updated_at: 2009-08-27 15:10:41
id: "1"
attended: f
lesson_register_id: "1"
attributes_cache: {}
BUT, when I type …
<%= debug lesson.lesson_register.attendees[0].created_at %>
I get …
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.created_at
Extracted source (around line **#7**):
7: <%= debug lesson.lesson_register.attendees[0].created_at %>
Can someone tell me what I’m doing wrong.
TIA
-Ants