# How can I link/anchor down the page with #anchor in urls?

**URL:** <https://www.ruby-forum.com/t/how-can-i-link-anchor-down-the-page-with-anchor-in-urls/62990>\
**Category:** Rails\
**Created:** [June 10, 2006, 5:02am UTC](https://www.ruby-forum.com/t/how-can-i-link-anchor-down-the-page-with-anchor-in-urls/62990 "2006-06-10T05:02:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfdesigner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@sfdesigner](https://www.ruby-forum.com/u/sfdesigner)\
**Post date:** [June 10, 2006, 5:02am UTC](https://www.ruby-forum.com/t/how-can-i-link-anchor-down-the-page-with-anchor-in-urls/62990/1 "2006-06-10T05:02:45Z")

</div>

I’m trying to expand on a blog tutorial and one thing I can’t figure out  
is how to use anchors within pages.

For example say I have sections on a page with anchors like \<a  
name=section1" through \<a name=section6". Using older non-rails  
methods I would construct urls that contains the pound symbol and anchor  
name in the url such as [http://www.foobar.com/page.html#section1](http://www.foobar.com/page.html#section1).  
Another practice I use to use is appending just the pound sign at the  
end of the url to jump to the top of the current page.

I’ve been able to append name/value pairs to the end of urls using  
hashes within link\_to statements. It seems the necessary question mark  
is added automagically before the name/value pair get added. I’m not  
sure how to add on to the url without the question mark being added.

Has anyone figured out a way to do that? I know there are a few other  
ways I could present the content using different approaches but I would  
like to figure out how to anchor down the pages if possible.

Thanks,  
DAN

---

<div class="post-metadata">

**Author:** ![sfdesigner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@sfdesigner](https://www.ruby-forum.com/u/sfdesigner)\
**Post date:** [June 10, 2006, 12:35pm UTC](https://www.ruby-forum.com/t/how-can-i-link-anchor-down-the-page-with-anchor-in-urls/62990/2 "2006-06-10T12:35:10Z")

</div>

sfdesigner sfdesigner wrote:

> Has anyone figured out a way to do that? I know there are a few other  
> ways I could present the content using different approaches but I would  
> like to figure out how to anchor down the pages if possible.

You can use :anchor with link\_to, e.g.

link\_to “Comments”,  
:controller =\> “post”,  
:action =\> “view”,  
:id =\> post.id,  
:anchor =\> “comments”

will generate something like:

/post/view/1#comments

–  
Philip R.  
[http://tzinfo.rubyforge.org/](http://tzinfo.rubyforge.org/) – DST-aware timezone library for Ruby

---

<div class="post-metadata">

**Author:** ![sfdesigner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@sfdesigner](https://www.ruby-forum.com/u/sfdesigner)\
**Post date:** [June 10, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/how-can-i-link-anchor-down-the-page-with-anchor-in-urls/62990/3 "2006-06-10T17:47:46Z")

</div>

I’ve been trying to figure this out as well so i hope you (Dan) don’t  
mind if i jump in here also and ask a question.

Is there a way to add the anchor from within the controller action that  
is rendering the page?  
basically, i have 3 forms on a page and if the second form does not  
validate i want to add an anchor to the page that references the second  
form so it will automatically scroll down to the errors.
