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)
Alphabetical Index <% @letters.each do |letter| %> <% letter_class = (letter == @initial) ? "letter_current" : "letter" %><%= link_to letter, { :action => “index”, :id => letter },
:class => letter_class %>
<% end %>
<%= render :partial => “search” %>
And the partial, rendered by the index page:
<% if @users and not @users.empty? %>
Name | Gender | Location | <%= link_to user.info.last_name, profile_for(user) %> <% end %> |
---|
<% 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