← Back to Upcase

Week 3, NoMethodError in Users#index


(Adam Lowe) #1

I have no idea why but I’m receiving the following error after 1:53 into the week three video:

NoMethodError in Users#index
undefined method `each’ for nil:NilClass

app/views/users/index.html.erb contains the following:

  <%= @users.each do |user| %>
  <div><%= link_to user.username, user %></div>
  <% end %>

I tried to go from the begining of the video with no luck.


(charlieanna) #2

Check if @users was defined in your index action inside your controller.


(Adam Lowe) #3
    class UsersController < ApplicationController
      respond_to :html
    
      def index
        @user = User.all
      end
.
.
.
end

(charlieanna) #4

This should be @users. You have @user.


(Adam Lowe) #5

Ah, thanks! I was pulling my hair out.