# Link\_to\_remote passing form values

**URL:** <https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585>\
**Category:** Rails\
**Created:** [March 30, 2007, 2:55am UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585 "2007-03-30T02:55:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 2:55am UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/1 "2007-03-30T02:55:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 4:00am UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/2 "2007-03-30T04:00:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 4:29am UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/3 "2007-03-30T04:29:52Z")

</div>

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’)”

---

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 8:43am UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/4 "2007-03-30T08:43:52Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 4:00pm UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/5 "2007-03-30T16:00:38Z")

</div>

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](http://groups.google.ca/group/rubyonrails-talk/msg/3df638d6c271d8c0)

Regards,  
Andy S.

---

<div class="post-metadata">

**Author:** ![reed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9de0a6/32.png) [@reed](https://www.ruby-forum.com/u/reed)\
**Post date:** [March 30, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/link-to-remote-passing-form-values/90585/6 "2007-03-30T15:09:30Z")

</div>

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
