Forum: Ruby on Rails Custom Pagination Links

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John T. (Guest)
on 2006-06-02 12:48
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!

<div class="pager">
  <%= link_to('&lt; 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}</span>"} %>
  <% end %>

  <%= link_to('Next &gt;', {:params => params.merge('page' =>
@my_pages.current.next)}, {:class => "nextlink"}) if
@my_pages.current.next %>
</div>
Xavier N. (Guest)
on 2006-06-02 14:24
(Received via mailing list)
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 %>
   <div class="pager">
   ...
   </div>
<% end %>

I normally factor that out to a helper.

-- fxn
John T. (Guest)
on 2006-06-02 15:22
Xavier N. wrote:

> <% if @my_pages.size > 1 %>
>    <div class="pager">
>    ...
>    </div>
> <% end %>
>
> I normally factor that out to a helper.
>
> -- fxn

Great, thanks a lot!
John T. (Guest)
on 2006-06-03 16:27
Just as a follow-up, @my_pages.size doesn't appear to work, but
@my_pages.page_count does.

John
This topic is locked and can not be replied to.