Flowdock
method

remote_form_for

Importance_5
v1.1.6 - Show latest stable - 5 notes - Class: ActionView::Helpers::PrototypeHelper
remote_form_for(object_name, *args, &proc) public

Works like form_remote_tag, but uses form_for semantics.

Show source
Register or log in to add new notes.
August 13, 2008
7 thanks

Update element after remote call

Not mentioned in the documentation, you can add :update option to the remote_form_for and pass the id of element you’d like to update after ajax action as you do with link_to_remote, for example:

<% remote_form_for "comment", :update => "form" } do |f| %>
  # your form here
<% end %>

Or

<% remote_form_for "comment", :update => {:success => "form", :failure => "errors"} do |f| %>
  # your form here
<% end %>
October 21, 2008
5 thanks

Using a Loading Graphic

If you want to make a little loading graphic, typically you use an animated gif (like a little spinner or something). Both link_to_remote and remote_form_for allow you to easily do this by using the :loaded and :loading triggers to call javascript.

For example:

<% remote_form_for @survey, :loading => "$('loading').show();", :loaded => "$('loading').hide();" do |f| %>
  <%= submit_tag ' Save' %>
  <%= image_tag "indicator_circle.gif", :style => 'display: none;', :id => 'loading' %>
<% end %>

The ‘loading’ parameter used for the ‘$’ prototype selector is the id of the animated gif. It starts out hidden, and is toggled by the loading/loaded triggers.

September 30, 2008
5 thanks

If you're not using resource

If you don’t use resource for your remote_form_for, then :url option is necessary.

For example:

<% remote_form_for "not_resource" do |f| ... %> 

won’t work. But with :url option, it will:

<% remote_form_for "not_resource", 
     :url => { :controller => "recommend", :action => "send" } do ... %> 
November 7, 2008
3 thanks

Re: Using a Loading Graphic

You probably want to be using :complete, not :loaded, to execute Javascript when an Ajax request has finished. See: http://prototypejs.org/api/ajax/options

January 18, 2011
2 thanks

Common AJAX options

See the documentation for link_to_remote to see the common AJAX options, like :before and :completed.