Devise not setting current_user on Ajax post even though correct x-csrf-token is included in request header

后端 未结 1 745
长情又很酷
长情又很酷 2021-01-12 09:15

Using: Rails 3.0.7 Devise 1.4.5 jquery-rails 1.0.14

When posting data via ajax, Devise is not setting current_donor.

My request header looks like this:

相关标签:
1条回答
  • 2021-01-12 10:00

    I had the same problem before. I solved it by including csrf_token as below

    $.ajax({
        type: "GET",
        url: url,
        data: params ,
        beforeSend: function(jqXHR, settings) {
            jqXHR.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
        },
        error: function(){
            alert("An error ocurred");
        },
        success: function(){
    
        }
    });
    
    0 讨论(0)
提交回复
热议问题