Hi There,
I'm following a tutorial to introduce a search feature.
It comprises of a series of boxes, (A-Z) which are links. These links
when clicked, trigger the search code in index (in infocontroller.rb)
Code below:
Info Controller:
def index
@title = "search"
@letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")
if params[:id]
@initial = params[:id]
infos = Info.find(:all,
:conditions => ["last_name like ?", @initial
+'%'],
:order => "last_name")
@users = infos.collect { |info| info.user }
end
end
The index page (where the search is performed)
<fieldset>
<legend>Alphabetical Index</legend>
<% @letters.each do |letter| %>
<% letter_class = (letter == @initial) ? "letter_current" : "letter"
%>
<%= link_to letter, { :action => "index", :id => letter },
:class => letter_class %>
<% end %>
<br clear="all" />
</fieldset>
<%= render :partial => "search" %>
And the partial, rendered by the index page:
<% if @users and not @users.empty? %>
<table class="users" border="0" cellpadding="5" cellspacing="1">
<tr class="header">
<th>Name</th> <th>Gender</th> <th>Location</th>
</tr>
<% @users.each do |user| %>
</td>
<td><%= link_to user.info.last_name, profile_for(user) %>
</tr>
<% end %>
</table>
<% end %>
For some odd reason, when I click the letter 'B' It throws an
exception: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.info
however, if I select any other letter, I have no problems.
What's going on?
Many Thanks
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.