Forum: Ruby on Rails form_remote_tag and :with

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David (Guest)
on 2008-10-03 10:43
(Received via mailing list)
I am trying to pass the result from a javascript function along with
the result from a text_field with form_remote_tag.  This is what I
have so far, but no go:

    <% form_remote_tag(:url => {:controller => 'requests', :action =>
'create'},  :with => "'data='+request()", :update => 'request_sent' )
do %>
        <%= text_field "request", "request" %><br/>
        <%= submit_tag 'Send Request' %>
    <% end %>

I was able to get this to work with link_to_remote with the following

<br/><%= link_to_remote 'Update availability', :url => {:action =>
"array"}, :with => "'data='+test()", :update => 'testing' %>

where test() is the javascript function.  This allows me to access the
result of the test function in params[:data].  It seems that I should
be able to do the same with form_remote_tag, but I have been
unsuccessful.   Maybe a syntax mistake?  Maybe not possible?
David (Guest)
on 2008-10-04 05:46
(Received via mailing list)
result() is the name of a javascript function that I have defined
within a script in the head element.  calling it in :with sets this
result to data, which can then be accessed with params[:data] in the
action create.

On Oct 3, 1:34 am, Frederick C. <removed_email_address@domain.invalid>
David (Guest)
on 2008-10-04 06:23
(Received via mailing list)
So this returns the correct value in params[:data]:
    <%= link_to_remote 'Send Request', :url => {:controller =>
"requests", :action => "create",
      :date => @date, :weekday => @weekday, :id => @id}, :with =>
      :update => 'request_sent' %>

but this returns nil:
        <% form_remote_tag(:url => {:controller => 'requests', :action
          :with => "'data='+newFunction()", :update => 'request_sent')
do %>
        <%= text_field "request", "request" %><br/>
        <%= submit_tag 'Send Request' %>

am I using :with within the form_remote_tag helper correctly?  Are you
able to use it with form_remote_tag?  Thanks.

On Oct 3, 1:46 am, Frederick C. <removed_email_address@domain.invalid>
David (Guest)
on 2008-10-04 06:33
(Received via mailing list)
Oh i forgot to include the <% end %> code.  I have that and it still
does not work.
David (Guest)
on 2008-10-17 09:01
(Received via mailing list)
can anyone help with this syntax?  I figure anything that works for
link_to_remote has got to work for form_remote_tag.  Does anyone know
if its possible to use the :with to pass parameters using
form_remote_tag?  This is what I have so far, but the params[:time]
passed in :with is still nil and it works with link_to_remote.

    <%= form_remote_tag :url => {:controller => 'requests', :action
=>'create', :month => @month,
        :day_number => @day_number, :day_name => @day_name, :id =>
        :with => "'time='+timeReturn()", :update => 'request_sent'  %>
        <%= text_field "request", "request" %><br/>
        <%= submit_tag('Send Request') %>
    <% end -%>

All the other params, i.e. month and day_number are passed, so i know
the general syntax is working, its just the :with that is giving me a
David (Guest)
on 2008-10-17 10:37
(Received via mailing list)
turns out you need to use submit_to_remote:

<% form_tag :url => {:controller => 'foo', :action =>'bar', :month =>
    :day_number => @day_number, :day_name => @day_name, :id => @id} do
      <%= text_field "request", "request" %><br/>
      <%= submit_to_remote('submit', 'Send Request', :url =>
{:controller => 'foo', :action =>'bar', :month => @month,
          :day_number => @day_number, :day_name => @day_name, :id =>
          :with => "'time='+timeReturn()", :update =>
'request_sent', :confirm => "sure?") %>
<% end %>
This topic is locked and can not be replied to.