Skip to content

Instantly share code, notes, and snippets.

@McKinneyDigital
Created June 6, 2012 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McKinneyDigital/2884425 to your computer and use it in GitHub Desktop.
Save McKinneyDigital/2884425 to your computer and use it in GitHub Desktop.
When using AJAX calls to rails methods, send CSRF token to validate the request
var csrf_token = $('meta[name=csrf-token]').attr('content');
$("body").bind("ajaxSend", function(elm, xhr, s){
if (s.type == "POST") {
xhr.setRequestHeader('X-CSRF-Token', csrf_token);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment