# Help with a daft question....:-)

**URL:** <https://www.ruby-forum.com/t/help-with-a-daft-question/189786>\
**Category:** Rails\
**Created:** [June 7, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/help-with-a-daft-question/189786 "2010-06-07T18:47:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 7, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/help-with-a-daft-question/189786/1 "2010-06-07T18:47:27Z")

</div>

Hello, I am hoping somwone can help with this…

Basically I have a website and I want to display a list of users  
currently using the site, prior to someone logging in.

In a sense, it is a way for people to view a profile before logging  
in, and then they can choose whether or not to add them as a friend,

SO - I have a login page which contains a link to a partial:

\<%= render :partial =\> “user/friendlist” %\>

in the friendlist file I have the following:

\<% @users.each do |user| %\>

\<%= link\_to thumbnail\_tag(user), profile\_for(user) %\>  
\<%= link\_to user.username, profile\_for(user) %\>

\<% end %\>

However, the login page cannot render with this code as it complains  
about a nil object: (see below)

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

What do I need to amend or add in oder for this to work?

Kind regards & thanks for reading

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 7, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/help-with-a-daft-question/189786/2 "2010-06-07T19:08:31Z")

</div>

On 7 June 2010 17:45, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<% end %\>
> 
> However, the login page cannot render with this code as it complains  
> about a nil object: (see below)
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.each
> 
> What do I need to amend or add in oder for this to work?

You have not shown us the trace so we can see which line it failed on.  
Have a look at that, if it is the @users.each line then this suggests  
that you have not put anything in @users, which you should be doing in  
the controller. I suggest you have a look at the Rails Guide (google  
if necessary) on debugging which will help you when you want to break  
in and have a look at your variables.

To achieve what you want you will have to load @users with currently  
logged in users.

Colin

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 7, 2010, 7:25pm UTC](https://www.ruby-forum.com/t/help-with-a-daft-question/189786/3 "2010-06-07T19:25:30Z")

</div>

It is that line that it is complaining about…

However my user controller must have this already as i burgled the  
code from another page that displays a list of pending friends…

i’ll do some more digging - thanks

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 7, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/help-with-a-daft-question/189786/4 "2010-06-07T19:54:12Z")

</div>

- sorted \*

I added @users = User.all and it returned all users

I can take it from there now…

On 7 June, 18:24, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
