Created
April 7, 2013 23:11
-
-
Save benschwarz/5333009 to your computer and use it in GitHub Desktop.
Set the CSRF token for Rails when doing Ajax requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define( ['jquery'], function ( $ ) { | |
var token = $( 'meta[name="csrf-token"]' ).attr( 'content' ); | |
$.ajaxSetup( { | |
beforeSend: function ( xhr ) { | |
xhr.setRequestHeader( 'X-CSRF-Token', token ); | |
} | |
}); | |
return token; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I ask you how to create this cookie in Rails? On
ApplicationController
maybe? On every NON-GET action?