returning image in my search results

Hi There,

I'm looking to improve my search results by allowing a thumbnail of
returned users to be displayed,

I currently have a table that shows:

<th> thumbnail here </th> <th>Last Name <th>Gender</th> <th>Location</

<th>Preference</th>

what i'd like is to be able to add the user's thumbnail to it.

So far I have my search results page:

  <td><%= user.info.lastname %></td>
  <td><%= user.info.location %></td>
  <td><%= user.info.pref %></td>

I tried to add the following:
  <% @user.friends.each do |friend| %>

<%= link_to thumbnail_tag(friend), profile_for(friend) %>

  <% end %>

Unfortunately, this returns with:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.friends

I know it's to do with the <% @user.friends.each do |friend| %> line,
but i can't seem to overcome this, despite an evening of google
searches.

Can anyone help?

thanks :slight_smile:

Hi There,

I'm looking to improve my search results by allowing a thumbnail of
returned users to be displayed,

I currently have a table that shows:

<th> thumbnail here </th> <th>Last Name <th>Gender</th> <th>Location</
> <th>Preference</th>

what i'd like is to be able to add the user's thumbnail to it.

So far I have my search results page:

   &lt;td&gt;&lt;%= user\.info\.lastname %&gt;&lt;/td&gt;
   &lt;td&gt;&lt;%= user\.info\.location %&gt;&lt;/td&gt;
   &lt;td&gt;&lt;%= user\.info\.pref %&gt;&lt;/td&gt;

I tried to add the following:
<% @user.friends.each do |friend| %>

<%= link_to thumbnail_tag(friend), profile_for(friend) %>

   &lt;% end %&gt;

Unfortunately, this returns with:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.friends

That suggests that @user is nil. I notice that above you have user not @user

Colin

Hi There,

I'm looking to improve my search results by allowing a thumbnail of
returned users to be displayed,

I currently have a table that shows:

<th> thumbnail here </th> <th>Last Name <th>Gender</th> <th>Location</
> <th>Preference</th>

what i'd like is to be able to add the user's thumbnail to it.

So far I have my search results page:

   &lt;td&gt;&lt;%= user\.info\.lastname %&gt;&lt;/td&gt;
   &lt;td&gt;&lt;%= user\.info\.location %&gt;&lt;/td&gt;
   &lt;td&gt;&lt;%= user\.info\.pref %&gt;&lt;/td&gt;

I tried to add the following:
<% @user.friends.each do |friend| %>

<%= link_to thumbnail_tag(friend), profile_for(friend) %>

   &lt;% end %&gt;

Unfortunately, this returns with:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.friends

I know it's to do with the <% @user.friends.each do |friend| %> line,
but i can't seem to overcome this, despite an evening of google
searches.

Can anyone help?

Hopefully.
You're referencing user.info.lastname, user.info.location,
user.info.pref and @user.friends. Note the @, that makes reference to
an instance variable which might not exist. you'd probalby wanted to
say user.friends there.

thanks :slight_smile:

NP.

hi,

Thanks for the replies...

I tried user.friends, and nothing happened. Well, i didn't get an
image anyway.

How would i need to combine the user.friends line witht he actual path
to the image: <%= link_to thumbnail_tag(friend), profile_for(friend)
%>?

cheers

Well... that depends on what are you using those files, I would
strongly recommend using paperclip or attachment_fu.
If you're uploading/handling your files by hand, you should be the one
who knows where your files are stored and you'll be responsible for
building the image path.

Hello... +1 for paperclip or attachment_fu; they will make this a lot
easier for you.

Earlier this year I wrote a detailed tutorial on how to setup and use
Paperclip in a new Rails application. Coincidentally, my example was
to attach photos to users and then to show different size photos. At
the bottom, I explain how to display a thumbnail for each user in a
table, similar to what you're trying to do.

See: http://patshaughnessy.net/2009/4/30/paperclip-sample-app

- pat