authenticity-token

Invalid Auth Token with Rails, Graphql, Apollo Client

好久不见. 提交于 2019-12-03 08:03:38
I am trying to get a basic Rails, Graphql, Apollo-Client setup working but having trouble with 422 errors 'invalid auth token' on the rails side. Does my use of apollo look wrong? It is a Rails 5 app with graphql gem and apollo client. const csrfToken = document.getElementsByName('csrf-token')[0].content const client = new ApolloClient({ networkInterface: createNetworkInterface({ uri: '/graphql', credentials: 'same-origin', headers: { 'X-CSRF-Token': csrfToken } }), }); client.query({ query: gql` query Camillo2 { user { id email created_at } } `, }) .then(data => console.log(data)) .catch

Proper way to send an Authenticity Token with AJAX to Rails

冷暖自知 提交于 2019-11-28 04:53:18
This works but gets stopped because it lacks an authenticity token: $(".ajax-referral").click(function(){ $.ajax({type: "POST", url: $(this).parent("form").attr("action"), dataType: "script"}); return false; }); So I tried adding it like so: $(".ajax-referral").click(function(){ $.ajax({type: "POST", url: $(this).parent("form").attr("action") + "?&authenticity_token=" + AUTH_TOKEN, dataType: "script"}); return false; }); And it passes the auth_token correctly as a param, but seems to lose the rest of my form. Anyways to accomplish both sending the form data that works, and the authenticity

Proper way to send an Authenticity Token with AJAX to Rails

故事扮演 提交于 2019-11-27 05:29:53
问题 This works but gets stopped because it lacks an authenticity token: $(".ajax-referral").click(function(){ $.ajax({type: "POST", url: $(this).parent("form").attr("action"), dataType: "script"}); return false; }); So I tried adding it like so: $(".ajax-referral").click(function(){ $.ajax({type: "POST", url: $(this).parent("form").attr("action") + "?&authenticity_token=" + AUTH_TOKEN, dataType: "script"}); return false; }); And it passes the auth_token correctly as a param, but seems to lose the

Rails 4 Authenticity Token

会有一股神秘感。 提交于 2019-11-26 04:57:36
问题 I was working on a new Rails 4 app (on Ruby 2.0.0-p0) when I ran into some authenticity token problems. While writing a controller that responds to json (using the respond_to class method), I got to the create action I started getting ActionController::InvalidAuthenticityToken exceptions when I tried to create a record using curl . I made sure I set -H \"Content-Type: application/json\" and I set the data with -d \"<my data here>\" but still no luck. I tried writing the same controller using

Understanding the Rails Authenticity Token

为君一笑 提交于 2019-11-25 22:43:59
问题 I am running into some issues regarding the Authenticity Token in Rails, as I have many times now. But I really don\'t want to just solve this problem and go on. I would really like to understand the Authenticity token. Well, my question is, do you have some complete source of information on this subject or would you spend your time to explain in details here? 回答1: What happens When the user views a form to create, update, or destroy a resource, the Rails app creates a random authenticity