Jeff C. wrote:
I want append custom query parameters to my pagination links, like
?page=1&foo=bar. I can’t quite figure out how to do this
Here’s what I did to implement a prefix search that if I understand your
request has a similar requirement - in the controller action spec (.rb
file) if the prefix parameter was set it would use the following custom
paginator instead of the one generated by the scaffold generator:
@performer_pages = Paginator.new self,
Performer.count, 25, @params[‘page’]
@performers = Performer.find( :all,
:conditions => [“Performer >= ?”, params[:prefix] ],
:order => “Name ASC”, :limit =>
@performer_pages.items_per_page,
:offset => @performer_pages.current.offset )
Then in the view (rhtml), to create the next & previous links I add the
prefix parameter to the URL if necessary:
<% if params[:prefix] %>
<%= link_to ‘Previous page’, { :prefix => params[:prefix], :page =>
@performer_pages.current.previous } if @performer_pages.current.previous
%>
<%= link_to ‘Next page’, { :prefix => params[:prefix], :page =>
@performer_pages.current.next } if @performer_pages.current.next %>
<% else %>
<%= link_to ‘Previous page’, { :page =>
@performer_pages.current.previous } if @performer_pages.current.previous
%>
<%= link_to ‘Next page’, { :page => @performer_pages.current.next } if
@performer_pages.current.next %>
<% end %>
Hope this helps.
PS: Only problem with my custom paginator is that while it seems to be
creating the next & previous links appropriately when they are required,
it creates the ‘next’ link when one is not required. Whereas it
appropriately generates the ‘previous’ link only when needed (i.e., not
on the first page of results), it consistently INappropriately generates
the ‘next’ link even when one is not required (i.e., the result for the
‘next’ page view is empty).
I suspect that this bug is somehow due to the way I generate the
paginator, whereas I gather all you’re asking for is about the creating
the next & previous links. Funny, because I copied this syntax exactly
from the docs.