问题描述:

What would be used more preferably?

What will work faster?

For example I need create some link. What use? <a> or link_to?

网友答案:

Stylistically, you may prefer this

<%= link_to "Users", users_path %>

to this

<a href="<%= users_path %>">Users</a>

mainly because it doesn't mix the HTML tags with the ERB quite as bad. It all stays in ERB.

Another reason probably doesn't apply to your situation right now but could apply in the future. The more view helpers like link_to that you use, the more globally configurable your application becomes. You may end up wanting to use a plugin in the future that globally modifies how link_to works, but obviously it wouldn't apply if you used straight up <a> tags.

网友答案:

link_to every time, otherwise you can't take advantage of routes etc

相关阅读:
Top