sfdesigner sfdesigner
2006-Jun-10 03:03 UTC
[Rails] How can I link/anchor down the page with #anchor in urls?
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"</a> through <a name=section6"</a>. 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. 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 -- Posted via http://www.ruby-forum.com/.
Philip Ross
2006-Jun-10 10:34 UTC
[Rails] Re: How can I link/anchor down the page with #anchor in urls?
sfdesigner sfdesigner wrote:> 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"</a> through <a name=section6"</a>. 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. > 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. > > 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 Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
Nate Constant
2006-Jun-10 15:48 UTC
[Rails] Re: How can I link/anchor down the page with #anchor in urls
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. -- Posted via http://www.ruby-forum.com/.