# Link\_to & others really necessary?

**URL:** <https://www.ruby-forum.com/t/link-to-others-really-necessary/119279>\
**Category:** Rails\
**Created:** [November 5, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/link-to-others-really-necessary/119279 "2007-11-05T18:54:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 5, 2007, 6:54pm UTC](https://www.ruby-forum.com/t/link-to-others-really-necessary/119279/1 "2007-11-05T18:54:58Z")

</div>

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?

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 5, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/link-to-others-really-necessary/119279/2 "2007-11-05T19:00:50Z")

</div>

Greg W. wrote:

> 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 🙂

Cheers,  
Mohit.  
11/6/2007 | 2:00 AM.

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 5, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/link-to-others-really-necessary/119279/3 "2007-11-05T19:06:08Z")

</div>

> So, before I dismiss them entirely, what’s the argument for using them?

Not having to remember as much syntax for one, and knowing that if  
prototype changes it’s API, I (most likely) won’t have to change my view  
code…

This:

\<% form\_remote\_tag :url =\> {:controller =\> ‘home’,  
:action =\> ‘get\_email’},  
:update =\> ‘notice’,  
:loading =\> “Element.show(‘indicator’);”,  
:complete =\> “Element.hide(‘indicator’);” do %\>

vs this:

Also link to will parse the arguments and build the appropriate route  
which your handcoded link won’t.

Most of the form tags will automatically set/check/etc the value if  
appropriate.

The asset tag helpers get you the file modification builtin and let you  
easily use asset hosts.

But you’re certainly not required to use them 🙂

-philip

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 5, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/link-to-others-really-necessary/119279/4 "2007-11-05T22:56:56Z")

</div>

The link\_to and friends really are one of the best things about the  
application.

link\_to “Home”, :action=\>“public”, :controller=\>“index”

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

```
 map.home '', :controller=>"public", :action=>"index"

```

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”

So I just change the route

map.home ‘’, :controller=\>“main”, :action=\>“index”

And all my links change.

How’s that?
