title: Submit form in rails 3 in an ajax way (with jQuery)
body: <p>I am a beginner in rails and jQuery. I have two separate forms in one page and I want to submit them separately in ajax way (with jQuery). This is how far I got. Can anybody add or fix this code to make it work. I am using Rails 3.1 and jQuery 1.6. Thank you in advance.   </p>
  
  <p>application.js</p>
  
  <pre><code>$(".savebutton").click(function() { 
      $('form').submit(function() {
           $(this).serialize();
      });
  }); 
  </code></pre>
  
  <p>first form:</p>
  
  <pre><code>&lt;%=form_for :users do |f| %&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Basic details&lt;/legend&gt;
      &lt;%= f.label :school %&gt;
      &lt;%= f.text_field :school,:size=&gt;"45",:class=&gt;"round",:id=&gt;"school" %&gt;&lt;br/&gt;      
    &lt;/fieldset&gt;
    &lt;p&gt;&lt;%= button_to "save and continue",{:class=&gt;"savebutton"} %&gt;&lt;/p&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>second form:</p>
  
  <pre><code>&lt;%=form_for :courses do |c| %&gt;
    &lt;fieldset&gt;
      &lt;legend&gt;Your current classes&lt;/legend&gt;
      &lt;label&gt;class:&lt;/label&gt;&lt;%= c.text_field :subject,:size=&gt;"45",:class=&gt;"round" %&gt;&lt;br/&gt;
    &lt;/fieldset&gt;
    &lt;p&gt;&lt;%= button_to "save and continue",{:class=&gt;"savebutton"} %&gt;&lt;/p&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>SchoolController</p>
  
  <pre><code>class SchoolController &lt; ApplicationController
    respond_to :json
    def create
      @school = current_user.posts.build(params[:school].merge(:user =&gt; current_user))
      if @school.save
        respond_with @school
      else
        respond_with @school.errors, :status =&gt; :unprocessable_entity
      end
    end
  end
  </code></pre>
  
  <p>CourseController is in the same shape as SchoolController</p>