Forum: Ruby on Rails NoMethodError

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
074d80d4c056f76b745721349da63b0e?d=identicon&s=25 Blaz (Guest)
on 2006-05-10 22:31
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: <table>
3: <% for user in @all_users %>
4: <tr>
5:   <th><%= user.name %></th>
-----------------------------------------------------
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 .... ??
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2006-05-10 22:44
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%>
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2006-05-10 22:45
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 :-)


<%if @all_users.nil?%>
   I have no users
<%else
   for user in @all_users%>
     do your html stuff
   <%end
end%>
074d80d4c056f76b745721349da63b0e?d=identicon&s=25 Blaz (Guest)
on 2006-05-10 22:50
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.
This topic is locked and can not be replied to.