[LRUG] AJAX file uploads and content types
Viktor Tron
viktor.tron at gmail.com
Wed Apr 4 03:00:48 PDT 2012
On Wed, 04 Apr 2012 09:29:12 +0100, Andrew Stewart
<boss at airbladesoftware.com> wrote:
> Morning El Rug,
>
> I have a Rails 3.0.11 app which does AJAX file uploads using the
> remotipart gem [1]. Everything works perfectly in development.
>
>
> In production I get 406 errors. I'd like to (a) find and fix the
> problem, and (b) work around it in the meantime.
>
> The basic process is this:
>
> 1) User submits a 'remote' form with a file input.
> 2) Remotipart's javascript intercepts the form submission, creates an
> iframe with the form data in it, and posts the iframe's form to the
> server (with content type text/html).
> 3) A remotipart middleware intervenes in the request to convert the
> request to text/javascript.
> 4) My controller action saves the image and responds by rendering
> create.js.erb.
>
> The problem seems to be at step 3. To gather more information I added
> `$stderr.puts "useful info"` etc to the remotipart middleware but I
> can't find the output in my unicorn logs.
>
> The 406 error is thrown at step 4 because my controller action only
> responds to javascript but the request is arriving as HTML.
then the problem is in step 1.
make sure you have :remote => true option in the form.
you could also try adding :format => :js to your route.
from rails 3.1 (but not in 3.0) file_field automatically adds :multipart
=> true to the enclosing form.
hth
> Can anyone shed any light on this?
>
> And in the meantime, can anyone tell me how to render my create.js.erb
> response even if the request wants html? I have tried various
> permutations in my respond_to block without success.
>
> Thank you!
>
> [1] https://github.com/JangoSteve/remotipart
> [2]
> https://github.com/JangoSteve/remotipart/blob/master/lib/remotipart/middleware.rb
>
> Cheers,
>
> Andy Stewart
> ----
> http://airbladesoftware.com
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
More information about the Chat
mailing list