An Ajax PUT request causes a logout in the Rails application. What for?

2 places in my Rails app have ajax calls. (one for jQueryUI drag and drop sort and one for comment update).

Whenever these calls occur, the user is logged out. For no apparent reason. I am using omniauth-facebook and omniauth-google-oauth2 for authentication.

How can this be fixed?

Here's an ajax call (coffeescript):

  $.ajax({
    type: 'put',
    data: {post_id: post.attr("id")},
    dataType: 'json',
    complete: -> post.children('.headpost').children('.buttons').removeClass('new_reply'),
    url: '/posts/update/'})

      

Thank!

+3


source to share


1 answer


What I ended up with:

In layout layout.html.erb under <%= csrf_meta_tags %>

:

<%= javascript_tag "var AUTH_TOKEN = '#{form_authenticity_token}';" if protect_against_forgery?%>

      



In assets /whatever.js.coffee

$.ajax ({
            type: 'put',
            data: {authenticity_token: AUTH_TOKEN},
            dataType: 'json',
            complete: -> post.children('.headpost').children('.buttons').removeClass('new_reply'),
            url: '/posts/'+post.attr("id").slice(5) });

      

+3


source







All Articles