Forum: Ruby on Rails Ajax/Rails question

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.
B31c8f5031486fa50ec7ee9e1350dec9?d=identicon&s=25 Marcus Blankenship (Guest)
on 2006-05-26 21:20
(Received via mailing list)
Is there any way to make an Ajax call (like link_to_remote) and pass in
the value of a field on screen?  This seems obvious, but I can't find
anything...

Thanks,
Marcus
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2006-05-27 01:31
Marcus Blankenship wrote:
> Is there any way to make an Ajax call (like link_to_remote) and pass in
> the value of a field on screen?  This seems obvious, but I can't find
> anything...


You could not use the helper and do this:

<a href="#" onclick="new Ajax.Updater(
			'resultsTarget',
			url,
			{ method: 'get',
			  parameters: pars,
                          onComplete: function(request) { alert('all
done'); }
			}); return false;">link</a>

Where url is the url of your controller/action and pars are the params
you wanna pass.

or write your own helper that does this. Didn't see a way to do it with
the existing one.

:-)
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-05-27 09:00
(Received via mailing list)
He's probably talking about the field value at the time the link is
clicked.  This can be done with the :with => parameter.  Look into it.
 If you need more help let me know.

Michael
2da252cc1d2fb3701126171831b50a65?d=identicon&s=25 Dave Coleman (pezdude)
on 2006-05-27 15:42
Michael Trier wrote:
> He's probably talking about the field value at the time the link is
> clicked.  This can be done with the :with => parameter.  Look into it.

ah... would be nice if the api docs had that as part of link_to_remote
options.

Found it under observe_field

:with
"A JavaScript expression specifying the parameters for the
XMLHttpRequest. This defaults to â??valueâ??, which in the evaluated context
refers to the new field value. If you specify a string without a "=",
itâ??ll be extended to mean the form key that the value should be assigned
to. So :with => "term" gives "â??termâ??=value". If a "=" is present, no
extension will happen."

Thanks! will try that.
This topic is locked and can not be replied to.