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 %>
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:
- <%= link_to note.body, notes_path( note.id ) %>
8: <% @notes.each do |note| %>
9:
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