baldowl/rack_csrf — pull request #4 by jeffreyiacono (2012-02-15 00:37:26+00:00)
Title: add csrf token validation in via request header, add metatag helper

Adds csrf token validation via request headers.

Useful for situations when using ajax: instead of having to pass the csrf token via params, we can now set a metatag with the csrf token's value in the layout's head and use something along the lines of:

(function(jQuery) {
// set the x-csrf-token for each ajax operation
// rack / rack_csrf handle the rest
jQuery.ajaxSetup({
beforeSend: function(xhr) {
var token = jQuery('meta[name="_csrf"]').attr('content');
xhr.setRequestHeader('X-CSRF-TOKEN', token);
}
});
}(jQuery));

now the csrf token is always sent on ajax requests via the specified header. Also adds a metatag helper to quickly generate the metatag with the token in place for the developer.

Additionally adds a Gemfile for gem packaging and updates the readme.