diff options
author | Michael Koziarski <michael@koziarski.com> | 2011-01-13 11:05:52 +1300 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-08 14:57:34 -0800 |
commit | 11061f410eca48c3a1922ade001bc54927e6b8c7 (patch) | |
tree | e27bd46edc2a57b957549f922167d067bc2bdb4b /railties/lib/rails/generators | |
parent | ae19e4141f27f80013c11e8b1da68e5c52c779ea (diff) | |
download | rails-11061f410eca48c3a1922ade001bc54927e6b8c7.tar.gz rails-11061f410eca48c3a1922ade001bc54927e6b8c7.tar.bz2 rails-11061f410eca48c3a1922ade001bc54927e6b8c7.zip |
Make rails.js include the CSRF token in the X-CSRF-Token header with every ajax request.
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js b/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js index 4c18cb0c3e..2cd1220786 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js +++ b/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js @@ -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; + } + } + }); })(); |