# Custom Pagination Links

**URL:** <https://www.ruby-forum.com/t/custom-pagination-links/62292>\
**Category:** Rails\
**Created:** [June 2, 2006, 10:48am UTC](https://www.ruby-forum.com/t/custom-pagination-links/62292 "2006-06-02T10:48:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [June 2, 2006, 10:48am UTC](https://www.ruby-forum.com/t/custom-pagination-links/62292/1 "2006-06-02T10:48:21Z")

</div>

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 %\>

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [June 2, 2006, 12:24pm UTC](https://www.ruby-forum.com/t/custom-pagination-links/62292/2 "2006-06-02T12:24:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [June 2, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/custom-pagination-links/62292/3 "2006-06-02T13:22:46Z")

</div>

Xavier N. wrote:

> \<% if @my\_pages.size \> 1 %\>
> 
> ... 
> \<% end %\>
> 
> I normally factor that out to a helper.
> 
> – fxn

Great, thanks a lot!

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [June 3, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/custom-pagination-links/62292/4 "2006-06-03T14:27:33Z")

</div>

Just as a follow-up, @my\_pages.size doesn’t appear to work, but  
@my\_pages.page\_count does.

John
