# Highlight and pagination

**URL:** <https://www.ruby-forum.com/t/highlight-and-pagination/106077>\
**Category:** Rails\
**Created:** [June 6, 2007, 6:43am UTC](https://www.ruby-forum.com/t/highlight-and-pagination/106077 "2007-06-06T06:43:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [June 6, 2007, 6:43am UTC](https://www.ruby-forum.com/t/highlight-and-pagination/106077/1 "2007-06-06T06:43:01Z")

</div>

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]
      end

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

```

“%”+params[:suche]+"%"],  
:include =\> [:member],  
:per\_page =\> 3

end

view:

\<% if @description %\>

\<%= highlight(link.description, @highlight, highlighter = '\1') %\>
\<% else %\>
\<%= 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?

Thanx

---

<div class="post-metadata">

**Author:** ![jawosis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f04885/32.png) [@jawosis](https://www.ruby-forum.com/u/jawosis)\
**Post date:** [June 6, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/highlight-and-pagination/106077/2 "2007-06-06T18:36:06Z")

</div>

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 = ‘\1’) %\>

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

HTH,  
Kevin
