will_paginate ?

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 ... <ul> <% @notes.each do |note| %>   <li><%= link_to note.body, notes_path( note.id ) %> </li> <% end %> </ul> <%= 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: <em>Searching for <%= @query %>...</em> 6: 7: <ul> 8: <% @notes.each do |note| %> 9: <li><%= link_to note.body, notes_path( note.id ) %> </li> 10: <% end %> 11: </ul>

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

This looks promising: 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.

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

This looks promising:http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_tag

...