Skip to content

Instantly share code, notes, and snippets.

View sudhirsb2003's full-sized avatar
:octocat:

Sudhir Vishwakarma sudhirsb2003

:octocat:
View GitHub Profile
@sudhirsb2003
sudhirsb2003 / gist:1064701
Created July 5, 2011 11:50
Naive CSRF-protection: Rails 3 and Ext.js 4's Ext.data.RestProxy
Ext.define('Ext.rails.ForgeryProtection', {
csrfParams: function() {
var params = {};
var metaCsrfParam = Ext.select('meta[name=csrf-param]').item(0);
var metaCsrfToken = Ext.select('meta[name=csrf-token]').item(0);
if (metaCsrfParam != undefined && metaCsrfToken != undefined) {
var name = metaCsrfParam.getAttribute('content');
var value = metaCsrfToken.getAttribute('content');
if (name != undefined && value != undefined) {
params[name] = value;