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 8410009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:04:15+00:00 2026-06-10T00:04:15+00:00

i’m trying to create a list of the items from my database. the problem

  • 0

i’m trying to create a list of the items from my database. the problem is that i cant acces in my view/user/index.html.erb the variable(array) from my users_controller methods. I have been reading tuts and books but the way they tell me to crushes somewhere on the way. Any hint/help is appreciated, Thank you.

Controller:

class UsersController < ApplicationController
  def index
    render('list')
  end

  def list
    @users = User.all
  end
  def show
    @user = User.find(params[:id])
  end
  def new
    @user = user.new
  end
  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = "User succesfully created!"
      redirect_to(:action => 'list')
    else
      flash[:notice] = "User couldn't be created!"
      render('new')
    end
  end
end

list.html.erb

<table>
    <tr>
    <td>
        <th>Name
    </td>
    <td>
        <th>Password
    </td>
    <td>
        <th>Log status
    </td>
    <td>
        <th>Warning
    </td>
    <td>
        <th>Banned
    </td>
    </tr>

    <% @users.each do |u| %>

    <tr>
        <td><%= u.name %></td>
        <td><%= u.password %></td>
        <td><%= u.log_status %></td>
        <td><%= u.warning %></td>
        <td><%= u.banned %></td>
    </tr>
    <%end%>
</table>

Error:

 NoMethodError in Users#index

Showing /home/bogdan/ex/lynda/hW/app/views/users/list.html.erb where line #20 raised:

undefined method `each' for nil:NilClass
Extracted source (around line #20):

17:     </td>
18:     </tr>
19: 
20:     <% @users.each do |u|%>
21: 
22:     <tr>
23:         <td><%= u.name %></td>
  • 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-10T00:04:17+00:00Added an answer on June 10, 2026 at 12:04 am

    Because you are rendering a view without having the variables used in it:

    Quick solution:

    add this in your index action and then hit reload:

     @users = User.all
    

    Detailed answer:

    These two methods are action(execution cursor) go to another place ,whether it is view or action.It means transfer control to one place to another place. Those are example for dry principle but different uses.

    “RENDER:”

    Render has something to do with just rendering that part of the view without actually running the method again.It means if we use render method it go to corresponding view so it did not go to server with any request so it is fast.But it use data in that method means where it render from.
    render also using for text,layout,file,template .

    “REDIRECT:”

    Redirect actually takes you to the page and does stuff from scratch. When we call redirect_to method it goes to that particular method
    , it means this request go to server and then go to method and execute it
    Ex:Example

      def update 
          @product= Product.find(params[:id]) 
         if @product.update_attributes(params[:name]) 
           redirect_to :action => 'list_users' 
         else 
           render :edit 
         end 
       end 
    

    Explanation:

    The above example if name update go to list_users method else go back to edit view.In this if updated user name then go to list users and display list of users and their values ,if not back to edit if not update data cause of any validation or any thing back to view

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is

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.