title: Rails 3: Jquery code breaks when making simple AJAX call, think is a simple mistake
body: <p>Looking to update the User model, in the devise registrations controller. </p>
  
  <p>In my view I have </p>
  
  <pre><code>&lt;%= form_for(@user, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; { :method =&gt; :put, :id =&gt; 'share-form' }, :remote =&gt; true) do |f| %&gt;  
  
               &lt;%= f.check_box :facebook_share  %&gt;
               &lt;%= f.label :facebook_share, :class =&gt; 'submit-share' %&gt;
  
              &lt;% end %&gt;
  </code></pre>
  
  <p>So the form has the id="share-form", I have a url and method specified.</p>
  
  <p>When my Jquery is the form is submitted normally, but the database is not updated with any data: </p>
  
  <pre><code>$(document).ready(function(){
  
      $('.submit-share').click(function() {
          $('#share-form').submit();    
      });
  });
  </code></pre>
  
  <p>Console reads :</p>
  
  <pre><code>Started POST "/users" for 127.0.0.1 at 2014-07-25 13:34:21 +0700
    Processing by RegistrationsController#update as HTML
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"GrQWqDseCwhlrpNhv8i3hvlL4iwae0U/pP+wSu4iabk=", "user"=&gt;{"facebook_share"=&gt;"0"}}
    User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 31 LIMIT 1
    CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 31 LIMIT 1
    SQL (0.8ms)  SELECT 1 FROM "users" WHERE (LOWER("users"."email") = LOWER('drew@drew.io')) AND ("users".id &lt;&gt; 31) LIMIT 1
    SQL (0.1ms)  SELECT COUNT(*) FROM "authentications" WHERE ("authentications".user_id = 31)
    CACHE (0.0ms)  SELECT COUNT(*) FROM "authentications" WHERE ("authentications".user_id = 31)
    CACHE (0.0ms)  SELECT COUNT(*) FROM "authentications" WHERE ("authentications".user_id = 31)
    SQL (0.1ms)  SELECT 1 FROM "users" WHERE ("users"."username" = 'facebookname') AND ("users".id &lt;&gt; 31) LIMIT 1
    Slug Load (0.7ms)  SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 31 AND "slugs".sluggable_type = 'User') ORDER BY id DESC LIMIT 1
    CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 31 LIMIT 1
  Redirected to http://localhost:3000/
  Completed 302 Found in 361ms
  </code></pre>
  
  <p>When I add this ajax call to update the data, the submit does not work and nothing happens. Where am I going wrong?? <strong><em>And the console says nothing</em></strong></p>
  
  <pre><code>$(document).ready(function(){
  
      $('.submit-share').click(function() {
          $('#share-form').submit(function(){
            $.ajax({
              method: this.method,
              url: this.action,
              data: $('#share-form').serialize()
            });         
          });
      });  
  });
  </code></pre>
  
  <p>I am confused, I think it has to be a simple mistake, thank you very much.</p>