remote_form_for
- 1.0.0
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (36)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
remote_form_for(object_name, *args, &proc)
public
Works like form_remote_tag, but uses form_for semantics.
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 %>
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.
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 ... %>
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
Common AJAX options
See the documentation for link_to_remote to see the common AJAX options, like :before and :completed.