1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make rails.js include the CSRF token in the X-CSRF-Token header with every ajax request.

This commit is contained in:
Michael Koziarski 2011-01-13 11:05:52 +13:00 committed by Aaron Patterson
parent ae19e4141f
commit 11061f410e

View file

@ -189,4 +189,20 @@
document.on('ajax:complete', 'form', function(event, form) {
if (form == event.findElement()) enableFormElements(form);
});
Ajax.Responders.register({
onCreate: function(request) {
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
if (csrf_meta_tag) {
var header = 'X-CSRF-Token',
token = csrf_meta_tag.readAttribute('content');
if (!request.options.requestHeaders) {
request.options.requestHeaders = {};
}
request.options.requestHeaders[header] = token;
}
}
});
})();