How can I use the link_to
helper to make a link without an href
attribute? I want to make a link exclusively for a javascript action, I don't want it reloading the page or anything.
When I omit the url parameter, clicking the link reloads the page. Ditto for providing nil
in place of the url.
The rails link_to is a helper which helps us in creating a hyperlink to the existing main document. The Rain link_to will be created as anchor tag or the h-ref tag. Anchor tag is known as an HTML code that creates another link to another page or to a specific section of the existing document.
Rails is able to map any object that you pass into link_to by its model. It actually has nothing to do with the view that you use it in. It knows that an instance of the Profile class should map to the /profiles/:id path when generating a URL.
open index. html. erb file in app>>views>>home folder use in atom editor. After you open index file now add following HTML link code in that file and end with <br /> tag.
In computing, a hyperlink, or simply a link, is a reference to data that the user can follow by clicking or tapping. A hyperlink points to a whole document or to a specific element within a document. Hypertext is text with hyperlinks.
You can also use a
content_tag("a","link text")
which gives you
<a>link text</a>
or, from the comment from @cesartalves, with a block:
content_tag("a") do image_tag("src") end
See: rails api
I use this approach:
= link_to('Click me', 'javascript:;', :id => :foo)
Its basically a Javascript no-op
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With