# DRYing up link\_to

**URL:** <https://www.ruby-forum.com/t/drying-up-link-to/77150>\
**Category:** Rails\
**Created:** [November 24, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150 "2006-11-24T19:40:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 24, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/1 "2006-11-24T19:40:32Z")

</div>

In reading DHH’s post about RC1, it dawned on me that we could  
potentially DRY up link\_to even more. Notice the redundancy in the  
examples in the docs?\*

link\_to “Delete this page”, { :action =\> “delete”, :id =\> @page.id },  
:confirm =\> “Are you sure?”  
link\_to “Help”, { :action =\> “help” }, :popup =\> true  
link\_to “Busy loop”, { :action =\> “busy” }, :popup =\> [‘new\_window’,  
‘height=300,width=600’]  
link\_to “Destroy account”, { :action =\> “destroy” }, :confirm =\> “Are  
you sure?”, :post =\> true

All of these could be rewritten without the action parameter, since  
action = name.split(’ ').first.downcase, which could give us elegant  
statements like this:

link\_to “Help”, :popup =\> true

What are your thoughts?

- I modified the first doc example to use a delete action instead of  
destroy to more clearly illustrate the idea

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 24, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/2 "2006-11-24T20:08:35Z")

</div>

D. Scott B. wrote:

> All of these could be rewritten without the action parameter, since  
> action = name.split(’ ').first.downcase, which could give us elegant  
> statements like this:
> 
> link\_to “Help”, :popup =\> true
> 
> What are your thoughts?

I’m gonna go write linky() to do that and call link\_to().

(Aphorism: There is no “DRY” in API!)

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 24, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/3 "2006-11-24T22:21:14Z")

</div>

allow me to point out that you should be using button\_to for the  
delete/destroy action

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 25, 2006, 3:40am UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/4 "2006-11-25T03:40:06Z")

</div>

Keynan P. wrote:

> allow me to point out that you should be using button\_to for the  
> delete/destroy action

Perhaps someone could correct that in the docs?

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 24, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/5 "2006-11-24T22:41:24Z")

</div>

On 11/24/06, D. Scott B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> link\_to “Destroy account”, { :action =\> “destroy” }, :confirm =\> "Are
> 
> - I modified the first doc example to use a delete action instead of  
> destroy to more clearly illustrate the idea

You’re assumign the link name corresponds to the action, which is a  
pretty big assumption.

link\_to “remove post”, { :action =\> “delete”,…}  
link\_to “read post”, { :action =\> “show”, …}  
etc…

Fine for a plugin, but definitely not baked in.

- rob

–

> **[Home](https://robsanheim.com/)**
>
> Just another WordPress site

> **[Seeking Alpha | Stock Market Analysis & Tools for Investors](https://seekingalpha.com/)**
>
> Join Seeking Alpha, the largest investing community in the world. Get stock market news and analysis, investing ideas, earnings calls, charts and portfolio analysis tools.

[http://www.ajaxian.com](http://www.ajaxian.com)

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 25, 2006, 3:46am UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/6 "2006-11-25T03:46:07Z")

</div>

D. Scott B. wrote:

> Keynan P. wrote:

> > allow me to point out that you should be using button\_to for the  
> > delete/destroy action
> 
> Perhaps someone could correct that in the docs?

I think it’s a semantic distinction. Like the hallowed CUA used to say  
“a dialog box is for brief interaction, such as presenting one  
question to the user”. Then we’d use one to occupy the “form” concept,  
and some dipshit consultant would catch us and ask us if we read the  
CUA. When we gave it to him with shrink-wrap on it, my colleague said,  
“Well, we read it, but then we put the shrinkwrap back on it.”

Where was I? Oh, yeah - destructive actions should - semantically - be  
behind buttons and POSTs, not A HREFs and GETs.

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![DSScott\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea5d25/32.png) [@DSScott\_B](https://www.ruby-forum.com/u/DSScott_B)\
**Post date:** [November 25, 2006, 3:48am UTC](https://www.ruby-forum.com/t/drying-up-link-to/77150/7 "2006-11-25T03:48:07Z")

</div>

We’re also assuming that the table names correspond to model names,  
which is a pretty big assumption. Just like in ActiveRecord, you’d  
still be able to manually specify an :action, but this seems like a  
textbook case where Rails can again leverage intelligent defaults.
