One of the areas where I think Rails goes too far is in many of the
helpers that (AFAICT) do nothing more than change the syntax used to
write simple HTML tags. link_to and many of the form tags come to mind.
For me, these helpers aren’t that helpful. I find the HTML much
clearer to write and read, I don’t see any added value in the
overhead costs of using code to generate a simple HTML tag. I have
written several code generators for complicated stuff like producing
sortable, paginated lists, so I’m not against generating HTML, just
not generating individual tags.
So, before I dismiss them entirely, what’s the argument for using them?
So, before I dismiss them entirely, what’s the argument for using them?
– gw
I guess it’s easier to read for one (IMHO) but doesn’t link_to also
allow you to create a link that’s a little more complex without thinking
about it, e.g. considering the controller and the action and the popups
and the confirms (OK, I’m just reading this off the API) and the method
(POST, delete, etc.) Also, I can’t remember if it takes care of routes
also…
Either way, I guess you can ignore (dismiss) it till it you need it
That’s nice, because it will build /public/index/ for me, no matter what
level of my app I’m in. I don’t have to worry about parent paths, nested
structures, etc.
But it gets better. If I define a named route in routes.rb
Now, without changing links, the link_to example I used above will
render a
link to /
And now that I have a named route, I can shorten that code to
link_to “Home”, home_url
That’s even better, because now someone might come along and decide that
the
homepage needs to be moved into a different controller, like “main”
because
they don’t like “public”