Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:45:36+00:00 2026-06-18T06:45:36+00:00

I was trying out ruby on rails through the tutorial located at http://ruby.railstutorial.org .

  • 0

I was trying out ruby on rails through the tutorial located at http://ruby.railstutorial.org.
I got to to the point where I could create users and have their name and gravatar displayed at:

http://localhost:3000/users/1

Now I want to display all users when a user goes to:

http://localhost:3000/users/

Here is my controller:

class UsersController < ApplicationController

  def index
    @user = User.all
  end      

  #...
end

Here is my view.

#View for index action in user's controleer

<h1>All users</h1>

<ul class="users">
  <% @users.each do |user| %>
    <li><%= user.content %></li>
  <% end %>
</ul>

I get the following error.

undefined method `each' for nil:NilClass

Can someone tell me why the index page is not working as I want it to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:45:37+00:00Added an answer on June 18, 2026 at 6:45 am

    The problem comes from the @users variable that does not exists:

    In your index action you set @user to all users:

    def index
      @user = User.all
    end
    

    By convention, we use pluralized names when we retrieve several entries from the DB, that’s why you are calling @users (notice the ‘s’) in the view. Just rename your @user to @users and it will be okay 😉

    def index
      @users = User.all
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently going through a RoR tutorial ( http://railstutorial.org/chapters/sign-in-sign-out#sec:signin_success is the relevant section) which
I'm trying to create a ruby gem for rails out of a plugin I've
Came across this error when trying out the ruby on rails tutorial section with
I'm trying to learn to use Ruby on Rails (going through Hartl's tutorial for
I'm trying to learn ruby on rails. I've been going through a tutorial, but
I'm trying to walk through Hartl's Ruby on Rails tutorial whilst upgrading his examples
I'm trying to figure out a way to take a Ruby array and create
I have been trying to figure out the following excerpt from Ruby on Rails
Am trying out Ruby on Rails in Windows XP using the Hello World example.
I am working through chapter 1 of the Ruby on Rails 3 Tutorial I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.