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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2010 17:45, RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On 7 June, 18:06, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 7 June 2010 17:45, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > 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? > > 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
* 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 <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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 > > On 7 June, 18:06, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > On 7 June 2010 17:45, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > 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? > > > 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.