# Destructive behavior with link\_to, button\_to, :post=\>true

**URL:** <https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242>\
**Category:** Rails\
**Created:** [January 22, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242 "2006-01-22T20:44:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/1 "2006-01-22T20:44:10Z")

</div>

Hello-

I would like to know what the suggested practice is for having multiple  
submit buttons on a relatively complicated input page.

Let’s use the example of a Contact. There is lots of info there,  
including name, address, phone number. There is also a list of “contact  
associations” which can be modified on the same page.

Ideally, the user could have one “Update” button to update all the  
regular information and then another button to do the “Add contact  
association”. But each association would also have a “Delete” button  
to remove that association.

It’s been suggested that POSTs be used for delete behavior rather than  
regular links. My typical way of doing this is to use “submit tags”  
within forms. But these aren’t well suited for inline behavior since  
you can’t nest forms and they also have problems since they are blocks.

So, what’s the “right” way to do this? link\_to with the :post=\>true?  
button\_to (not my favorite due to the nested form difficulty)

Jake

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 8:54pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/2 "2006-01-22T20:54:14Z")

</div>

Jake J. wrote:

> link\_to with the :post=\>true?

This works pretty well

\_Kevin

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/3 "2006-01-22T21:08:09Z")

</div>

Kevin O. wrote:

> Jake J. wrote:
> 
> > link\_to with the :post=\>true?
> 
> This works pretty well
> 
> \_Kevin

Great. Now, to add to the question a bit – what if I have a selection  
of those contacts and want to relay which one was selected to the  
link\_to w/post?

Do I need to add a Javascript thing to go fetch that value from the  
selection item? Then add the selected “id” to the link?

Jake

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/4 "2006-01-22T21:26:54Z")

</div>

Jake J. wrote:

> Kevin O. wrote:
> 
> > Jake J. wrote:
> > 
> > > link\_to with the :post=\>true?
> > 
> > This works pretty well
> > 
> > \_Kevin
> 
> Great. Now, to add to the question a bit – what if I have a selection  
> of those contacts and want to relay which one was selected to the  
> link\_to w/post?
> 
> Do I need to add a Javascript thing to go fetch that value from the  
> selection item? Then add the selected “id” to the link?
> 
> Jake

link\_to {:action=\>‘action’, :id=\>object.id}, {:post=\>true}

\_Kevin

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/5 "2006-01-22T21:33:40Z")

</div>

Kevin O. wrote:

> Jake J. wrote:
> 
> > Kevin O. wrote:
> > 
> > > Jake J. wrote:
> > > 
> > > > link\_to with the :post=\>true?
> > > 
> > > This works pretty well
> > > 
> > > \_Kevin
> > 
> > Great. Now, to add to the question a bit – what if I have a selection  
> > of those contacts and want to relay which one was selected to the  
> > link\_to w/post?
> > 
> > Do I need to add a Javascript thing to go fetch that value from the  
> > selection item? Then add the selected “id” to the link?
> > 
> > Jake
> 
> link\_to {:action=\>‘action’, :id=\>object.id}, {:post=\>true}
> 
> \_Kevin

Yes, but the problem is that the data I’d like to send along with the  
link\_to action is within form elements. Using a normal submit/form  
would send this along with the POST, but not the link\_to.

I think I’m better off just tweaking my form to suit what is possible  
here.

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/6 "2006-01-22T22:50:24Z")

</div>

Tom M. wrote:

> On Jan 22, 2006, at 12:26 PM, Kevin O. wrote:
> 
> > > Do I need to add a Javascript thing to go fetch that value from the  
> > > selection item? Then add the selected “id” to the link?
> > > 
> > > Jake
> > 
> > link\_to {:action=\>‘action’, :id=\>object.id}, {:post=\>true}
> 
> link\_to {:action=\>‘action’, :id=\>object}, {:post=\>true}
> 
> .id is assumed.
> 
> Rails is about less code… 🙂
> 
> –  
> – Tom M.

Yeah, I know. I prefer to be a little more explicit when writing  
examples in case the reader didn’t know that. Actually I think it calls  
the to\_param method so it can really be anything.

\_Kevin

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 22, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/destructive-behavior-with-link-to-button-to-post-true/64242/7 "2006-01-22T22:42:38Z")

</div>

On Jan 22, 2006, at 12:26 PM, Kevin O. wrote:

> > Do I need to add a Javascript thing to go fetch that value from the  
> > selection item? Then add the selected “id” to the link?
> > 
> > Jake
> 
> link\_to {:action=\>‘action’, :id=\>object.id}, {:post=\>true}

link\_to {:action=\>‘action’, :id=\>object}, {:post=\>true}

.id is assumed.

Rails is about less code… 🙂

–  
– Tom M.
