Posting DELETE requests via AJAX

27 views
Skip to first unread message

planon

unread,
Mar 25, 2011, 4:19:37 AM3/25/11
to Devise
I'm trying to use AJAX to send a DELETE request to a controller that
uses a before filter to authenticate the user. But even if the user is
logged in, the request via AJAX fails due to authentication issues,
and then kick the user off if he cancels the http-simple-auth dialogue
that pops up . How can I make a request to a controller to delete
something even if the controller is protected without running into
this issue?

Gary Taylor

unread,
Mar 25, 2011, 4:53:40 AM3/25/11
to plataforma...@googlegroups.com
I have just had the same problem. It was related to the 'X-CSRF-Token' header in the ajax call not being present. This was due to upgrading rails, but not the rails.js file which deals with all of this. It relies on you using the csrf_meta_tag helper in the <head> of your page - this generates a couple of meta tags with the forgery protection token / value in it.

Hope this helps

Gary

Reply all
Reply to author
Forward
0 new messages