Need HELP changing link_to_remote to a button

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

On 7/21/06, Bill W. [email protected] 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
[email protected]
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?

Hi Daniel,

Daniel N wrote:

On 7/21/06, Bill W. [email protected] 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

On 7/21/06, Bill W. [email protected] wrote:


Rails mailing list
[email protected]
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 :slight_smile:

Hi Daniel,

Daniel N wrote:

On 7/21/06, Bill W. [email protected] wrote:

Hi Daniel,

Daniel N wrote:

On 7/21/06, Bill W. [email protected] 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

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
[email protected]
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs