Skip to content

Instantly share code, notes, and snippets.

@coffeencoke
Created February 1, 2012 17:03
Show Gist options
  • Save coffeencoke/1718055 to your computer and use it in GitHub Desktop.
Save coffeencoke/1718055 to your computer and use it in GitHub Desktop.
Session clears when making ajax requests in Rails 3.0.4+
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
}}
);
@coffeencoke
Copy link
Author

Use this if you are getting issues with your session clearing when making ajax requests. In previous rails versions you would receive invalid session authenticity token, but now, it just clears the session silently and slyly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment