Forum: Ruby on Rails Destructive behavior with link_to, button_to, :post=>true

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2006-01-22 20:44
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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-22 20:54
Jake Janovetz wrote:
> link_to with the :post=>true?

This works pretty well

_Kevin
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2006-01-22 21:08
Kevin Olbrich wrote:
> Jake Janovetz 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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-22 21:26
Jake Janovetz wrote:
> Kevin Olbrich wrote:
>> Jake Janovetz 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
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2006-01-22 21:33
Kevin Olbrich wrote:
> Jake Janovetz wrote:
>> Kevin Olbrich wrote:
>>> Jake Janovetz 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.
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-01-22 22:42
(Received via mailing list)
On Jan 22, 2006, at 12:26 PM, Kevin Olbrich 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 Mornini
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-22 22:50
Tom Mornini wrote:
> On Jan 22, 2006, at 12:26 PM, Kevin Olbrich 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 Mornini

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
This topic is locked and can not be replied to.