public Method

PrototypeHelper.submit_to_remote(name, value, options = {})

Returns a button input tag with the element name of name and a value (i.e., display text) of value that will submit form using XMLHttpRequest in the background instead of a regular POST request that reloads the page.

# Create a button that submits to the create action
#
# Generates: <input name="create_btn" type="button" value="Create" onclick="new Ajax.Request('/testing/create',
#     {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
#     return false;" />
<%= submit_to_remote 'create_btn', 'Create', :url => { :action => 'create' } %>

# Submit to the remote action update and update the DIV succeed or fail based
# on the success or failure of the request
#
# Generates: <input name="update_btn" type="button" value="Update" onclick="new Ajax.Updater({success:'succeed',failure:'fail'},
#      '/testing/update', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
#      return false;" />
<%= submit_to_remote 'update_btn', 'Update', :url => { :action => 'update' },
   :update => { :success => "succeed", :failure => "fail" }

options argument is the same as in form_remote_tag.

Source Code

# File action_view/helpers/prototype_helper.rb, line 412
def submit_to_remote(name, value, options = {})
  options[:with] ||= 'Form.serialize(this.form)'

  options[:html] ||= {}
  options[:html][:type] = 'button'
  options[:html][:onclick] = "#{remote_function(options)}; return false;"
  options[:html][:name] = name
  options[:html][:value] = value

  tag("input", options[:html], false)
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.