I am learning Rails and I have noticed that Rails continously uses helper method such as link_to instead of just using plain html. Now I can understand why they would use they would use some helper methods, but I don’t understand why they would prefer helper methods over just coding the html directly. Why does Rails prefer helper method instead of you having to write the html manually? Why did the Rails team make this design choice?
I am learning Rails and I have noticed that Rails continously uses helper method
Share
In Rails apps, links are often generated using both methods for URL and methods for content, e.g.
That’s definitely more manageable than putting those into the
<a>tags manually.(You are using the router for generating those URLs, right? What happens if you hardcode
/users/1and decide that you want it to be/users/1-John-Doelater?)For static links, though, it doesn’t really matter much.
One could make a case for the former for performance or the latter for consistent style, since both are equally manageable.