Forum: Ruby on Rails highlight and pagination

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jochen K. (Guest)
on 2007-06-06 08:43
(Received via mailing list)
I made a search-field which shows all hits and highlights the all
words searched for:

  def suche

          if params[:link][:suchfeld] == "description"
              @description = "show"
              @highlight = params[:suche]

        @link_pages, @links =
            paginate :link, :order_by => 'url',
            :conditions => ["#{params[:link][:suchfeld]} LIKE ?",
            :include => [:member],
            :per_page => 3



<% if @description %>
<div class="link_initial_description" id="link<%= %>">
<%= highlight(link.description, @highlight, highlighter = '<strong
class="highlight">\1</strong>') %>
<% else %>
<div class="link_initial_description" style="display:none"
id="link<%= %>">
<%= link.description %>
<% end  %>
<%= pagination_links(@link_pages) %>

Everything works fine when I get only 1 result page. When I get
more pages and click the pages_link highlighting no longer works.

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.[]

WHat can I do?

Kevin S. (Guest)
on 2007-06-06 20:36
(Received via mailing list)
Sounds like when you go to the second page, you no longer have
params[:link][:suchfeld] set.

Also, there may not be a reason to set @highlight = params[:suche].
The params are available to the View and you can just do:
<%= highlight(link.description, params[:suche], highlighter = '<strong
class="highlight">\1</strong>') %>

But I think your problem isn't the highlighting, it's that the action
suche is expecting params[:link][:suchfeld].

This topic is locked and can not be replied to.