Submitting Forms Using Rails and AJAX

August 17, 2007

Recently, I have been toying around with Rails and the Scriptaculous libraries.  I wanted to be able to have a user drag a div which contained a form into a box.  When the div was dragged into said box, I wanted the form to be submitted.  Automatically.

Since I am new to Rails myself, I had a quite difficult time figuring this one out.  After searching around for an hour or so and finding nothing but info about remote_form_for helpers, I finally came across this page: http://wiki.rubyonrails.org/rails/pages/observe_form+-+Passing+Parameters

This page, using the observe_form helpers, uses Prototype’s Form.serialize( ‘id’ ) method to automatically submit a form using AJAX.  This is more-or-less exactly what I needed to do!

If only I had studied the Prototype library more before jumping in.  I hope this can help somebody else at some point.