Cameron Bass Cameron Bass - 6 months ago 3x
Ruby Question

Getting an undefined method `each' for nil:NilClass

I understand what this error is saying but I don't know why I'm getting it? I'm trying to display a table with the index action, everything seems pretty standard but for some reasons this error has occurred. I'll post my code for clarity.


<table class="table table-striped">
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<% @subsriber.each do |subsriber| %>
<td><%= subscriber.first_name %></td>
<td><%= subscriber.last_name %></td>
<td><%= %></td>
<td><%= subscriber.phone_number %></td>
<% end %>


def index
@subscriber = Subscriber.all

I know I must be missing something simple. Thanks for the help!


A typo error, in your controller you defined @subscriber but used @subsriber in the view!

Btw, conventionally, You may use @subscribers instead of @subscriber, it is clearer!