Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    rails json csrf_token error

    Version: SmartClient LGPL 8.2
    Rails version: 3.2.3

    If you lost your session, and your are doing a some requests to the server with post methods with json format and you get the warning message "WARNING: Can't verify CSRF token authenticity" and lost your session. You have to send in the header of the request in the DataSource (im ny case RestDataSource) the X-CSRF-Token.

    Code:
        transformRequest: function(dsRequest){
            dsRequest.httpHeaders = new Object();
            var token = $("meta[name='csrf-token']").attr("content");
            dsRequest.httpHeaders['X-CSRF-Token'] = token;
            return this.Super("transformRequest", arguments);
        },
    I hope this helps other people as well :-)
Working...
X