Custom Pagination Links


#1

Hi,

I’m using the code below to display some pagination links. It works
great apart from when there’s no paging i.e. the full collection is
displayed, when it still display a “1” to represent the current page.
How can I suppress that?

Thanks!

<%= link_to('< Prev', {:params => params.merge('page' => @my_pages.current.previous)}, {:class => "prevlink"}) if @my_pages.current.previous %>

<% for page in @my_pages -%>
<%= link_to_unless(params[:page].to_i == page.number, page.number,
{:params => params.merge(‘page’ => page)},
{:class => “pagelink”}) {|link_name|
“<span class=“currentpage”>#{link_name}”} %>
<% end %>

<%= link_to(‘Next >’, {:params => params.merge(‘page’ =>
@my_pages.current.next)}, {:class => “nextlink”}) if
@my_pages.current.next %>


#2

On Jun 2, 2006, at 10:48, John T. wrote:

Hi,

I’m using the code below to display some pagination links. It works
great apart from when there’s no paging i.e. the full collection is
displayed, when it still display a “1” to represent the current page.
How can I suppress that?

<% if @my_pages.size > 1 %>

...
<% end %>

I normally factor that out to a helper.

– fxn


#3

Xavier N. wrote:

<% if @my_pages.size > 1 %>

...
<% end %>

I normally factor that out to a helper.

– fxn

Great, thanks a lot!


#4

Just as a follow-up, @my_pages.size doesn’t appear to work, but
@my_pages.page_count does.

John