supahken
supahken

Reputation: 161

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.

Upvotes: 6

Views: 1474

Answers (1)

Bill Turner
Bill Turner

Reputation: 3697

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.

Upvotes: 5

Related Questions