Link_to_remote passing form values

I need to call a remote function passing data from the current page
which a user has enterred.

Trying to do things the rails way the closest I could get was this…
<%= link_to_remote ‘Remote Call’, :url => {:action =>
‘add_device’,:serial=>"$(‘serial’).value"} %>

It doesn’t work though because it makes the “$(‘serial’).value” url
safe and passes this string instead of the field value. Note: I
tried :escape => false but that didn’t help.

Below works but is ugly.

Remote Call

Does anyone know a better better way to achieve this?

Thanks, Reed

Hi Reed,
reed wrote:

I need to call a remote function passing data from
the current page which a user has enterred.

Trying to do things the rails way the closest I could get was this…
<%= link_to_remote ‘Remote Call’, :url => {:action =>
‘add_device’,:serial=>"$(‘serial’).value"} %>

Try
<%= link_to_remote ‘Remote Call’, :url => {:action =>
‘add_device’,::with =>
“name_of_param_you_want_to_use_in_
your_controller_to_access_the_value_of_the_field”} %>

hth,
Bill

Bill W. wrote:

Hi Reed,
reed wrote:

I need to call a remote function passing data from
the current page which a user has enterred.

Trying to do things the rails way the closest I could get was this…
<%= link_to_remote ‘Remote Call’, :url => {:action =>
‘add_device’,:serial=>"$(‘serial’).value"} %>

Try
<%= link_to_remote ‘Remote Call’, :url => {:action =>
‘add_device’,::with =>
“name_of_param_you_want_to_use_in_
your_controller_to_access_the_value_of_the_field”} %>

hth,
Bill

Or to get everything…
:with => “Form.serialize(‘my_form’)”

Thanks for that I’m certainly closer to figuring this out than I was,
but I’m still having problems…

If I use submit to remote it works…
<%= submit_to_remote ‘submit_to_remote’, ‘add_device’, :url =>
{:action => ‘add_device’}%>
or
<%= submit_to_remote ‘submit_to_remote’, ‘add_device’, :url =>
{:action => ‘add_device’}, :with => “Form.serialize(this.form)” %>

But these don’t…
<%= link_to_remote ‘Add Device’, :url => {:action =>
‘add_device’},:with =>“serial” %>

<%= link_to_remote ‘Add Device’, :url => {:action =>
‘add_device’},:with =>“Form.serialize(this.form)” %>

<%= submit_to_remote ‘submit_to_remote’, ‘add_device’, :url =>
{:action => ‘add_device’}, :with => “serial” %>

On Mar 30, 2:29 pm, Jeff P. [email protected]

On 30 Mar 2007, at 07:43, reed wrote:

Thanks for that I’m certainly closer to figuring this out than I was,
but I’m still having problems…

I just encountered something similar so I hope the solution I found
helps you:

http://groups.google.ca/group/rubyonrails-talk/msg/3df638d6c271d8c0

Regards,
Andy S.

Hi Reed,

reed wrote:

Thanks for that I’m certainly closer to figuring this
out than I was, but I’m still having problems…

Actually, as I re-read your earlier posting, I see I really didn’t help
much
WRT passing back an input value using a link. With a link, you’d
definitely
need to include the value and I didn’t give you that. My bad. I
apologize
for not reading your post more carefully. Jeff showed you how to pass
back
all the form’s values. Using that approach, you could then pull the
param
value you wanted out of the hash. AFAIK, it’s a safe way to
‘pre-submit’
form values. Using submit_to_remote basically does the same thing, but
I
would bet it’s going to give you problems inasmuch as you’ll have more
than
one submit button within your form.

So let me ask… what exactly are you trying to accomplish? Is it just
one
user-entered value that you want to pass back? Is it important that the
visitor explicitly click a link or button to do that? If not,
observe_field
will let you pass a user_entered value quite easily. If it is more than
one
field you need to pass, or if you want the visitor to have to explicitly
submit the value, then it’ll take more. Let us know, before I start
guessing and giving you more bad advice ;-p

Best regards,
Bill