Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an advantage to using link_to over the anchor tag in Rails?

Don't these two do the same thing?

<%= link_to "Example", '#', class: "somestyle" %>

<a href="#" class= "somestyle"> Example </a>

If I'm writing a static .html.erb page, if everything else is written with HTML tags, doesn't it make sense to use HTML tags for links as well? I'm not sure why one should use a helper. Similarly, for linking style sheets, javascripts, etc.

like image 417
supahken Avatar asked Mar 07 '14 17:03

supahken


People also ask

Is hyperlink and anchor tag same?

The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page.

What is the difference between an anchor and a link element?

These are two different things. The anchor element is used to link to another page or to a certain part of the page if you use its ID. And The link tag defines a link between a document and an external resource. The link tag is used to link to external style sheets.

Which attribute is the most important attribute of an anchor tag?

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination.

What is the purpose of an anchor tag?

An anchor tag, or anchor link, is a web page element that links to another location on the same page. They are typically used for long or text-heavy pages so that visitors can jump to a specific part of the page without having to scroll as much.


1 Answers

For the link tags, it may not make a difference which way you go. Unless you're linking to more than "#". For instance, using a routed path.

For the stylesheets and javascript, I think you will need to continue to use the Rails helpers if you're taking advantage of the asset pipeline. If so, the hash in the filename changes at each asset compilation (I believe), and manually trying to edit the filename each time could become a pain.

like image 115
Bill Turner Avatar answered Oct 06 '22 00:10

Bill Turner