Skip to content

Instantly share code, notes, and snippets.

@monicao
Created September 9, 2012 15:26
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 monicao/3685044 to your computer and use it in GitHub Desktop.
Save monicao/3685044 to your computer and use it in GitHub Desktop.
Make $.ajax requests include the authenticity token
$.ajaxSetup(
beforeSend: (xhr, settings) ->
return if (settings.crossDomain || settings.type == "GET")
token = $('meta[name="csrf-token"]').attr('content')
xhr.setRequestHeader('X-CSRF-Token', token) if token
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment