# Pagination with anchor in URLs

**URL:** <https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493>\
**Category:** Rails\
**Created:** [February 14, 2007, 12:41am UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493 "2007-02-14T00:41:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/u/Ernst_BeiglbSSSSck)\
**Post date:** [February 14, 2007, 12:41am UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493/1 "2007-02-14T00:41:13Z")

</div>

Hi,  
I’m using standard rails pagination (I know it’s not perfect but it  
suits me humble needs).  
I want to add an anchor to the url.  
Like making  
article/2?page=5  
to  
article/2?page=5#content

I haven’t found an option in the paginator. Can someone help me please?

Thanks very much.

---

<div class="post-metadata">

**Author:** ![Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/u/Ernst_BeiglbSSSSck)\
**Post date:** [February 14, 2007, 12:44am UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493/2 "2007-02-14T00:44:36Z")

</div>

Ernst BeiglbÃ¶ck wrote:

> Hi,  
> I’m using standard rails pagination (I know it’s not perfect but it  
> suits me humble needs).  
> I want to add an anchor to the url.  
> Like making  
> article/2?page=5  
> to  
> article/2?page=5#content
> 
> I haven’t found an option in the paginator. Can someone help me please?
> 
> Thanks very much.

Use this one above to navigate down to where you want the scroll to go  
😃

---

<div class="post-metadata">

**Author:** ![Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/u/Ernst_BeiglbSSSSck)\
**Post date:** [February 14, 2007, 12:59am UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493/3 "2007-02-14T00:59:14Z")

</div>

Sorry, but you misunderstood me.  
I want that a command like  
\<%= pagination\_links(@slide\_pages) %\>  
appends #content to all URLs it generates.  
So that you have  
  
for example.

 

On 2/14/07, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
wer viel lest ist viel gebildet.

---

<div class="post-metadata">

**Author:** ![Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/u/Ernst_BeiglbSSSSck)\
**Post date:** [February 14, 2007, 1:05am UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493/4 "2007-02-14T01:05:15Z")

</div>

On 2/13/07, Ernst BeiglbÃ¶ck [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry, but you misunderstood me.  
> I want that a command like  
> \<%= pagination\_links(@slide\_pages) %\>  
> appends #content to all URLs it generates.  
> So that you have  
>   
> for example.

 

Just add something like this in your application\_helper.rb: (modify the  
next  
and previous to add #content.) So in your view you would call  
\<%=pagination(@slide\_pages)%\>.

 

```
def pagination(pages)
  rvalue = "<span id=\"pagination\">"
  if pages.current.previous
    rvalue << link_to('Previous page', { :action => 'list', :page =>

```

 

pages.current.previous})  
rvalue \<\< "&nbsp;&nbsp;|&nbsp;&nbsp;" if pages.current.next  
end

 

```
  if pages.current.next
    next_page = pages.current.next
    page_no = next_page.to_i - 1
    rvalue << %(pg. #{page_no} of #{pages.length})
    rvalue << "&nbsp;&nbsp;|&nbsp;&nbsp;"
    rvalue << link_to('Next page', { :action => 'list', :page =>

```

 

next\_page})  
end  
rvalue \<\< “”  
rvalue  
end

 

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/13edae/32.png) [@Ernst\_BeiglbSSSSck](https://www.ruby-forum.com/u/Ernst_BeiglbSSSSck)\
**Post date:** [February 14, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/pagination-with-anchor-in-urls/85493/5 "2007-02-14T16:46:51Z")

</div>

Thanks, it works

On 2/14/07, Andrew S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > for example.  
> > rvalue \<\< link\_to(‘Previous page’, { :action =\> ‘list’, :page =\>  
> > rvalue \<\< link\_to(‘Next page’, { :action =\> ‘list’, :page =\>

–  
wer viel lest ist viel gebildet.
