简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM