Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate link_to without path (only anchor)

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'

like image 871
ValeriiVasin Avatar asked Feb 27 '12 08:02

ValeriiVasin


2 Answers

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.

like image 125
abhishek Avatar answered Sep 20 '22 00:09

abhishek


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

like image 45
user1136228 Avatar answered Sep 18 '22 00:09

user1136228