Skip to content

Adding AJAX to forms

Ronald Chan edited this page Mar 13, 2012 · 2 revisions

This guide assumes you already have site-wide navigation set up.

Connecting your form up to AJAX Pagination is just as simple as with your links.

Simply change your current form_tag calls:

<%= form_tag posts_url, :method => "post", :class => "myclass" do %>
 ...
<% end %>

to use ajax_form_tag, and specify which section your new content should be displayed in using the :section_id option:

<%= ajax_form_tag posts_url, :method => "post", :class => "myclass", :section_id => "page" do %>
 ...
<% end %>

Or if you are using form_for:

<%= form_for @post, :method => "post", :html => {:class => "myclass"} do %>
 ...
<% end %>

Then use ajax_form_for instead

<%= ajax_form_for @post, :method => "post", :html => {:class => "myclass", :section_id => "menu"} do %>
 ...
<% end %>

For more on AJAX functionality in forms, see Creating AJAX forms including with other form helpers.