Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't verify CSRF token for a jQuery File Upload, IE 9 only, Rails 3 app

So I am using jquery file upload in a rails 3 app, and everything works beautifully, well except in IE 9 that is. Only in IE9, when I try to upload a file, I keep getting the 'cant verify csrf token' error in my console. I installed Firebug lite to inspect it, and the correct csrf token is correct and is in the right place in the document (and yes I have my <%= csrf_meta_tags %> tag in the header of layout file). Not sure why it is only doing this in IE 9, has anyone seen this before?

like image 798
ggrillone Avatar asked Aug 22 '12 13:08

ggrillone


1 Answers

I had the same issue and the comment above from the OP helped me find the answer. Here is what worked for me:

$('#fileupload').fileupload({
  ... other options
  formData: [
    { name: 'authenticity_token', value: $('meta[name="csrf-token"]').attr('content') }
  ]
});

Note that the layout file (application.html.erb in Rails 3.2) should have the following:

  <%= csrf_meta_tags %>
like image 191
Santosh Avatar answered Sep 21 '22 22:09

Santosh