Create link_to without path (binding only)

I need to have a path like "#privacy" for the tab plugin. The link should contain only the binding. When I use link_to 'Privacy', :anchor => 'privacy' Rails generate /privacy#privacy - a link that contains the full path and binding.

How can I tell Rails to generate a url without a path (binding only)?

Thanks.

Solved by : link_to 'Privacy', '#privacy'

+6
source share
4 answers

The following will create the link the way you want -

 link_to "my-privacy", "#privacy" 

In most browsers, the path to the current page will be prefix, but if you check the source of the page, the following html will be shown -

 <a href="#privacy">my-privacy</a> 

This will most likely serve your purpose for the user interface, you just have to split the URL into "#" using Javascript.

+9
source

This will work for you <% = link_to "title", resource_path (: anchor => "anchor")%>

+2
source

Route generation is not required, and a generator is not needed.

 <%= link_to "link text", "#", :id => 'your_id_here' %> 

You will need an identifier to access the object through jQuery.

//edit

 <%= link_to "link text", "/#anchor", :id => 'your_id_here' %> 
+1
source

Your best bet for this exact scenario is to simply use <%= link_to "link text", "#anchor" %> . The anchor tag is used in url_for and does not really give you an easy way to use the anchor.

0
source

Source: https://habr.com/ru/post/909433/


All Articles