method

form_remote_tag

Importance_3
Ruby on Rails latest stable (v7.1.3.2) - 1 note - Class: ActionView::Helpers::PrototypeHelper

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

form_remote_tag(options = {}, &block) public

Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it’s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in params). The options for specifying the target with :url and defining callbacks is the same as link_to_remote.

A "fall-through" target for browsers that doesn’t do JavaScript can be specified with the :action/:method options on :html.

Example:

  # Generates:
  #      <form action="/some/place" method="post" onsubmit="new Ajax.Request('',
  #      {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
  form_remote_tag :html => { :action =>
    url_for(:controller => "some", :action => "place") }

The Hash passed to the :html key is equivalent to the options (2nd) argument in the FormTagHelper.form_tag method.

By default the fall-through action is the same as the one specified in the :url (and the default method is :post).

form_remote_tag also takes a block, like form_tag:

  # Generates:
  #     <form action="/" method="post" onsubmit="new Ajax.Request('/',
  #     {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)});
  #     return false;"> <div><input name="commit" type="submit" value="Save" /></div>
  #     </form>
  <% form_remote_tag :url => '/posts' do -%>
    <div><%= submit_tag 'Save' %></div>
  <% end -%>
Show source
Register or log in to add new notes.
November 12, 2008
1 thank

Ajax form

<% form_remote_tag :url => { :action => “analyze”}, :update => “result” do %>

  <%= select_tag 'company_id', options_for_select([]) %><br/>
  <%= text_area_tag :text, nil, { :cols => 100, :rows => 10 }%><br/>
  <%= submit_tag "Analyze", :disable_with => "Please wait..." %>
<% end %>
<div id="result"></div>