NoMethodError


#1

When I want to see my users, then I get:


You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each

Extracted source (around line #3):

1: <% @page_title = “Spisek uporabnikov” -%>
2:


3: <% for user in @all_users %>
4:
5:

that’s list_users.rhtml ^

and login_controller.rb Ë?


def list_users
@all_users = User.find_all
end

And I don’t understand what is wrong here … ??

<%= user.name %>

#2

Blaz wrote:

3: <% for user in @all_users %>
And I don’t understand what is wrong here … ??

Looks like @all_users contains no users.

Try this:

<%if @all_users.nil?
I have no users
<%else
for user in @all_users%>
do your html stuff
<%end
<%end%>


#3

David C. wrote:

Blaz wrote:

3: <% for user in @all_users %>
And I don’t understand what is wrong here … ??

Looks like @all_users contains no users.

Try this:

without the typos :slight_smile:

<%if @all_users.nil?%>
I have no users
<%else
for user in @all_users%>
do your html stuff
<%end
end%>


#4

Thanx, but I just solved my problem.

there was

def /
end

before

def list_users
@all_users = User.find_all
end

and when i was remove that def / , all run fine.