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

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

On 7 June 2010 17:45, RubyonRails_newbie [email protected]
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

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

  • 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 [email protected]