# Need HELP changing link\_to\_remote to a button

**URL:** <https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148>\
**Category:** Rails\
**Created:** [July 20, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148 "2006-07-20T16:58:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/1 "2006-07-20T16:58:22Z")

</div>

I would really appreciate some help with changing a link\_to\_remote call  
to a button of some sort. Here’s a little background.

On the page there are two

s. One is a form that lets the visitor  
enter items. The second 
 is where the entered items get displayed,  
each in it’s own item 
.

Each item

 has two s. The first one displays the item  
description as entered in the form. The second contains a  
link\_to\_remote that allows the removal of the item from the database in  
the controller action and then removal of the item 
 from the page  
using RJS.

As I understand the discussion in AWDwR (p. 335-7), a visitor who has  
the Google Web Accelerator (GWA) installed is going to have a real  
problem unless I change the link\_to\_remote to a button. As I  
understand it, every time they add an item, GWA is going to follow that  
link and remove what they just added.

First, can anybody confirm (or even better, correct my understanding)  
that that’s the way GWA is going to work?

Second, assuming I’ve got a real problem, has anybody got any ideas  
about how to make this change? I’ve experimented a bit and the  
situation right now, using button\_to, is that the controller gets called  
and the database record gets deleted. When the RJS template gets  
called, however, and sends the JS to the browser to remove the item

 from the page, instead of executing the JS, the browser intercepts it and asks if I want to save it. I don't understand why or what I need to do to make this change work.

Sure would appreciate some help on this.

Thanks in advance,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/2 "2006-07-20T17:05:00Z")

</div>

On 7/21/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> link\_to\_remote that allows the removal of the item from the database in the  
> that’s the way GWA is going to work?
> 
> Thanks in advance,  
> Bill
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I don’t understand what’s happening with GWA but have you tried wrapping  
your button in a form\_remote\_tag?

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/3 "2006-07-20T17:14:57Z")

</div>

Hi Daniel,

> Daniel N wrote:

> On 7/21/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I would really appreciate some help with changing a  
> > link\_to\_remote call to a button of some sort.

> have you tried wrapping your button in a form\_remote\_tag?

No I haven’t. And I’m not sure I understand the suggestion. Do you  
mean  
wrapping or replacing? If I could wrap it, which I don’t think I can  
since,  
AFAIK, I can’t have a form within a form, it seems like that would give  
me  
two buttons. OTOH, I’ll take a look at the syntax for form\_remote\_tag  
and  
see if that might work. Thanks for the suggestion!

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/4 "2006-07-20T17:24:59Z")

</div>

On 7/21/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

If you are placing the button into the form then I’m not sure that you  
can  
put another form just around the button.

I’m guessing a bit here but I think you should be able to use the  
remote\_function method to get a remote function attached to the button,  
this  
is basically the same as a link\_to\_remote call

\<%= button\_to\_function “A name”, remote\_function( :url =\> { :action =\>  
‘my\_action’, :controller =\> ‘my\_controller’, :id =\> 2 }, :update =\>  
‘my\_div’  
), {:class =\> ‘a\_css\_class’} %\>

Hope that works 🙂

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 5:48pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/5 "2006-07-20T17:48:27Z")

</div>

Hi Daniel,

Daniel N wrote:

On 7/21/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Daniel,

> > Daniel N wrote:

> > On 7/21/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > I would really appreciate some help with changing a  
> > > link\_to\_remote call to a button of some sort.

> > have you tried … a form\_remote\_tag?

> I’ll take a look at the syntax for form\_remote\_tag and  
> see if that might work. Thanks for the suggestion!

It worked like a charm. SWEET!!! Thanks _very_ much for your  
suggestion!

For future readers…

As long as the following line is not contained within a form…

\<%= link\_to\_remote(“Remove”, :url =\> {:action =\> ‘destroy’, :id =\>  
@this\_allergy.id}) %\>

it can be replaced with the following to avoid the look-ahead,  
link-following issues caused by client-side agents like Google Web  
Accelerator.

\<%= form\_remote\_tag( :url =\> {:action =\> ‘destroy’, :id =\>  
@this\_allergy.id}) %\>  
\<%= submit\_tag “Remove” %\>  
\<%= end\_form\_tag %\>

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [July 20, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/need-help-changing-link-to-remote-to-a-button/99148/6 "2006-07-20T18:01:26Z")

</div>

On Thursday, July 20, 2006, at 10:47 AM, Bill W. wrote:

> > > > I would really appreciate some help with changing a
> 
> @this\_allergy.id}) %\>  
> \<%= submit\_tag “Remove” %\>  
> \<%= end\_form\_tag %\>
> 
> Best regards,  
> Bill
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I think you may also be able to do this…

\<%= link\_to\_remote(“Remove”, :url =\> {:action =\> ‘destroy’, :id =\>  
@this\_allergy.id}, {:post=\>true}) %\>

Which, IIRC, will prevent GWA from following the link.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)
