Skip to content

Instantly share code, notes, and snippets.

@mdp
Created February 2, 2012 22:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdp/1726303 to your computer and use it in GitHub Desktop.
Save mdp/1726303 to your computer and use it in GitHub Desktop.
Backbone AJAX Rails CSRF token hack
app.csrf_token = $('meta[name="csrf-token"]').attr('content')
$.ajaxSetup
beforeSend: (xhr, settings) ->
return if (settings.crossDomain)
return if (settings.type == "GET")
if (app.csrf_token)
xhr.setRequestHeader('X-CSRF-Token', app.csrf_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment