title: Jquery-File-Upload in Rails, Submitting Twice, JSON and HTML?
body: <p>I have a strange problem-- I have adapted code from the Jquery-File-Upload demo example into my app, and whenever I upload an image, it seems like the upload tries to post twice, once with JSON, and then once with HTML.</p>
  
  <p>The JSON Post is working correctly, but the HTML Post is posting null parameters, which triggers an error.</p>
  
  <p>I am confused, because I am literally copying the EXACT same files as the demo, out of box.  I added the 'Uploads' model, controller, views and routes to my app, and I'm literally just running the example from localhost:3000/uploads as a sanity test, and it's not working.  I have not changed any of the code from the demo, so I don't understand why its suddenly firing twice now.</p>
  
  <pre><code>Started POST "/uploads" for 127.0.0.1 at 2013-11-19 03:21:39 -0500
  Processing by UploadsController#create as JSON
  Parameters: {"utf8"=&gt;"✓",   "authenticity_token"=&gt;"SLkjXV0R/pEneunEUzHLOGJ3iKm4KLJgHrAudzWs5v4=", 
  "upload"=&gt;{"upload"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x007fbef632acf0 
  @original_filename="aliceten.png", @content_type="image/png", @headers="Content-
  Disposition: form-data; name=\"upload[upload]\"; filename=\"aliceten.png\"\r\nContent-
  Type: image/png\r\n", @tempfile=#
  &lt;File:/var/folders/sb/1k3xvfvn63d8p11mxry4zh6c0000gq/T/RackMultipart20131119-42740-vi3x5y&gt;&gt;}}
  (0.1ms)  BEGIN
   SQL (0.3ms)  INSERT INTO `uploads` (`created_at`, `updated_at`, `upload_content_type`,
   `upload_file_name`, `upload_file_size`, `upload_updated_at`) VALUES ('2013-11-19 08:21:39', '2013-11-19 08:21:39', 'image/png', 'aliceten.png', 5947, '2013-11-19 08:21:39')
  [paperclip] Saving attachments.
  [paperclip] saving /uploads/uploads/000/000/027/original/aliceten.png
  [AWS S3 200 0.79522 0 retries]    
  put_object(:acl=&gt;:public_read,:bucket_name=&gt;"elasticbeanstalk-us-west-2-
  859932007099",
  :content_length=&gt;5947,:content_type=&gt;"image/png",:data=&gt;Paperclip::UploadedFileAdapter: aliceten.png,:key=&gt;"uploads/uploads/000/000/027/original/aliceten.png")  
  
  (0.4ms)  COMMIT
  Completed 201 Created in 803ms (Views: 0.8ms | ActiveRecord: 0.7ms)
  
  
  Started POST "/uploads" for 127.0.0.1 at 2013-11-19 03:21:40 -0500
  Processing by UploadsController#create as HTML
  Parameters: {"utf8"=&gt;"✓", 
  "authenticity_token"=&gt;"SLkjXV0R/pEneunEUzHLOGJ3iKm4KLJgHrAudzWs5v4="}
  (0.1ms)  BEGIN
  SQL (0.2ms)  INSERT INTO `uploads` (`created_at`, `updated_at`, `upload_content_type`, 
  `upload_file_name`, `upload_file_size`, `upload_updated_at`) VALUES ('2013-11-19 
  08:21:40', '2013-11-19 08:21:40', NULL, NULL, NULL, NULL)
  [paperclip] Saving attachments.
  (0.4ms)  COMMIT
  Completed 200 OK in 3ms (Views: 0.1ms | ActiveRecord: 0.6ms)
  </code></pre>
  
  <p>In the Uploads#create function, the respond with does have layout set to false.  Not sure why its trying so hard to serve up HTML?</p>
  
  <pre><code>if @upload.save
      format.html {
        render :json =&gt; [@upload.to_jq_upload].to_json,
        :content_type =&gt; 'text/html',
        :layout =&gt; false
      }
      format.json { render json: {files: [@upload.to_jq_upload]}, status: :created, location: @upload }
    else
  </code></pre>