Reputation: 8706
I need to have path like "#privacy" for tab plugin. Link must contain only anchor. When I use link_to 'Privacy', :anchor => 'privacy'
Rails generate /privacy#privacy
- link, that contains full path and anchor.
How can I told Rails to generate url without path (only anchor)?
Thanks.
Solved: link_to 'Privacy', '#privacy'
Upvotes: 6
Views: 8671
Reputation: 977
This will work for you <%= link_to "title", resource_path(:anchor => "anchor") %>
Upvotes: 2
Reputation: 7458
Your best bet for this exact scenario is to just use <%= link_to "link text", "#anchor" %>
. The anchor tag is used within url_for
and doesn't really give you a clean way to just use an anchor.
Upvotes: 0
Reputation: 1008
The following will create a link the way you want -
link_to "my-privacy", "#privacy"
In most browsers, the path of the current page will be prefixed, but if you check the source of the page, the following html will be seen -
<a href="#privacy">my-privacy</a>
This will most probably serve your purpose for the UI, just that you'll have to split the url at '#' using Javascript.
Upvotes: 9
Reputation: 8954
No generation of routes is needed also no generator is needed.
<%= link_to "link text", "#", :id => 'your_id_here' %>
You will need the id to access the object via jQuery.
//edit
<%= link_to "link text", "/#anchor", :id => 'your_id_here' %>
Upvotes: 0