I am developing in Rails 3 and have a html document with the following structure:
<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
I can link to sections by going to the address: /index#one, /index#two and /index#three. Is it possible to give these a specific named route in rails? Something like:
match '/one', :to => 'pages#index#one'
match '/two', :to => 'pages#index#two'
match '/three', :to => 'pages#index#three'
I’d rather actually name the route, than put the hash into the address bar, if that makes sense.
Thanks in advance.
In the views, you can use the
:anchorparameter to modify the named routes, like this:That’s how I would do it.
Edit: I think I misunderstood your problem. You want completely distinct URLs which redirect to different anchors on an identical page, right?
Personally, I don’t think it’s a good idea, since if you have links to the different sections in the document, they will produce a page reload which is normally not necessary for anchors. You’d also need some JavaScript workaround for behavior which is automatically handled by the browser if done the usual way.