# Will\_paginate?

**URL:** <https://www.ruby-forum.com/t/will-paginate/182038>\
**Category:** Rails\
**Created:** [January 21, 2010, 10:06pm UTC](https://www.ruby-forum.com/t/will-paginate/182038 "2010-01-21T22:06:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [January 21, 2010, 10:06pm UTC](https://www.ruby-forum.com/t/will-paginate/182038/1 "2010-01-21T22:06:42Z")

</div>

Does anyone have experience with will\_paginate?

I’m trying to use it with acts\_as\_ferret.

routes.rb  
…  
map.search ‘/search’, :controller =\> ‘notes’, :action =\> ‘search’

notes.rb  
…  
acts\_as\_ferret :fields =\> [‘body’]

notes\_controller.rb  
…  
def search  
if params[:query]  
@query = params[:query]  
@notes = Note.find\_with\_ferret @query, :page =\> params  
[:page], :per\_page =\> 3  
end

```
respond_to do |format|
  format.html # search.html.erb
  format.xml { render :xml => @notes }
end

```

end

notes/index.html.erb  
…  
\<% if @notes.length \> 1 %\>  
\<% form\_tag :action =\> ‘search’, :patient\_id =\> @patient.id, :method  
=\> ‘get’ do %\>  
\<%= text\_field\_tag :query, nil, :size =\> 20 %\>  
\<%= submit\_tag “Search” %\>  
\<% end %\>  
\<% end %\>

notes/search.html.erb  
…

\<% @notes.each do |note| %\> - \<%= link\_to note.body, notes\_path( note.id ) %\> 
\<% end %\>
\<%= will\_paginate @notes, :params =\> { :patient\_id =\> @patient.id } %\>

The pagination list shows fine, but when clicking on a page number, I  
get the error:

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.each

Extracted source (around line #8):

5: _Searching for \<%= @query %\>…_  
6:  
7:

  
8: \<% @notes.each do |note| %\>  
9: - \<%= link\_to note.body, notes\_path( note.id ) %\> 
  
10: \<% end %\>  
11: 

The other, really dumb question I have is that the links generated by  
notes\_path( note.id ) take the form …notes.32 whereas my show method  
wants notes/32. How can I get notes\_path to correctly format?

Many TIA,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [January 21, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/will-paginate/182038/2 "2010-01-21T23:07:34Z")

</div>

Thanks, David. I ran across that link in my searches today, but the  
“UPDATE (6/6/08): This is out of date for the latest Rails and  
will\_paginate” threw me off a little.

I’ll give Sphinx a try–I’m certainly not married to act\_as\_ferret.  
Craig

On Jan 21, 3:21 pm, David [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This looks promising:[http://www.mckinneystation.com/2007/08/20/pagination-with-acts\_as\_tag](http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_tag)…

…

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [January 21, 2010, 10:22pm UTC](https://www.ruby-forum.com/t/will-paginate/182038/3 "2010-01-21T22:22:30Z")

</div>

This looks promising:  
[http://www.mckinneystation.com/2007/08/20/pagination-with-acts\_as\_taggable\_on\_steroids-acts\_as\_ferret-and-will\_paginate/](http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/)

You basically need to wrap the results from find\_with\_ferret in a  
WillPaginate collection so that the will\_paginate helper knows what to  
do with it. This is ordinarily accomplished with the “paginate” method  
when using ordinary finds, which find\_with\_ferret is not,  
unfortunately.

By the way, Sphinx is generally considered better than Ferret for  
search, and automatically returns will\_paginate collections…

If notes is a rest resource, you might want to try note\_path(note)  
instead of notes\_path.
