You have a nil object when you didn't expect it!

I’ve got a list of members in a sidebar using the code below. It works
great for the list page, but when I edit or add a new member I get
“You have a nil object when you didn’t expect it!” - I have a hunch
this is just a nooby mistake, but I’m at a loss. Any help would be
greatly appreciated!

<% for member in @members %>

  • <%= link_to h(member.first_name) + " " + h(member.last_name), edit_member_path(player) %>
  • <% end %>

    Kedron -

    On 31-Aug-07, at 10:27 PM, Kedron wrote:

    <% end %>

    Your log file will tell you more - like the line number (it’s a stack
    trace).

    generally one of your variables is a nil. The line number should help.

    You could try logging the values out. Some people would use the built
    in debugger to help out.

    cheers,
    Jodi

    On Aug 31, 10:32 pm, Jodi S. [email protected] wrote:

    greatly appreciated!

    You could try logging the values out. Some people would use the built
    in debugger to help out.

    cheers,
    Jodi

    Thanks Jodi for the quick response!

    The log says its the first line:

    <% for player in @players %>

    Kedron -

    On 31-Aug-07, at 10:44 PM, Kedron wrote:

    I’ve got a list of members in a sidebar using the code below. It

    Jodi

    Thanks Jodi for the quick response!

    The log says its the first line:

    <% for player in @players %>

    If that’s the case, then it can only be @players

    Your controller action for this view must set this collection. Go
    look at the action and verify that @players is set to a legitimate
    value.

    Cheers,
    Jodi

    or check if its nil before using it, so it doesnt throw any exception
    again :slight_smile:

    either this or that