Eugene
Eugene

Reputation: 689

Rails helpers or html tags?

What would be used more preferably? What will work faster?

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

Upvotes: 1

Views: 115

Answers (2)

Chris Peters
Chris Peters

Reputation: 18090

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.

Upvotes: 1

TomDunning
TomDunning

Reputation: 4877

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

Upvotes: 0

Related Questions