# Paginating a search

**URL:** <https://www.ruby-forum.com/t/paginating-a-search/196608>\
**Category:** Rails\
**Created:** [March 15, 2008, 11:31am UTC](https://www.ruby-forum.com/t/paginating-a-search/196608 "2008-03-15T11:31:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![javiel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8c91f0/32.png) [@javiel](https://www.ruby-forum.com/u/javiel)\
**Post date:** [March 15, 2008, 11:31am UTC](https://www.ruby-forum.com/t/paginating-a-search/196608/1 "2008-03-15T11:31:53Z")

</div>

hi!

I have been trying to use will\_paginate with acts\_as\_ferret and it works  
correctly in the first page, but nowhere else. When I try to see the  
second or any other page I get a nil object error while evaluating  
nil.each.

this is in the controller:

def search\_results  
if request.post?  
@profiles = Profile.find\_with\_ferret params[:query], :page  
=\>params[:page], :per\_page =\> 9

end

and in my view search\_results.rhtml I have this:

\<%= render(:partial =\> “shared/sidebar”) %\>

\<% for profile in @profiles %\> \<%= link\_to profile.name, :controller=\>'dogprofile', :action =\>'show', :id=\>profile %\> \<%end%\> \<%= will\_paginate @profiles %\>

As I said the first results page is ok, somehow It deletes the result  
collection when tries to access to another page.

any idea please?

thanks!

---

<div class="post-metadata">

**Author:** ![javiel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8c91f0/32.png) [@javiel](https://www.ruby-forum.com/u/javiel)\
**Post date:** [March 15, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/paginating-a-search/196608/2 "2008-03-15T17:26:39Z")

</div>

> > def search\_results  
> > if request.post?

You’re requiring a POST for your search results; the pagination links  
are just normal hyperlinks (i.e. GET requests). Either change your  
method to allow GET or hack will\_paginate to render links that  
generate a POST request (not recommended IMHO)

---

<div class="post-metadata">

**Author:** ![javiel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8c91f0/32.png) [@javiel](https://www.ruby-forum.com/u/javiel)\
**Post date:** [March 16, 2008, 6:00pm UTC](https://www.ruby-forum.com/t/paginating-a-search/196608/3 "2008-03-16T18:00:45Z")

</div>

Jeff Emminger wrote:

> > > def search\_results  
> > > if request.post?
> 
> You’re requiring a POST for your search results; the pagination links  
> are just normal hyperlinks (i.e. GET requests). Either change your  
> method to allow GET or hack will\_paginate to render links that  
> generate a POST request (not recommended IMHO)

Thanks Jeff!
