Form remote: true authenticity_token disappear

181 Views Asked by At

If I set remote: true to my form authenticity_token disappear. I have to add authenticity_token: true to my form? What about caching? If I cache the form I have to add authenticity_token: true? Is a problem that authenticity_token is cached? Thank you

1

There are 1 best solutions below

0
calebkm On BEST ANSWER

Are you using the jquery-rails gem in your app? This'll add the CSRF token to remote: true AJAX form submissions automagically:

https://github.com/rails/jquery-rails/blob/master/vendor/assets/javascripts/jquery_ujs.js#L69

// Make sure that every Ajax request sends the CSRF token
CSRFProtection: function(xhr) {
  var token = rails.csrfToken();
  if (token) xhr.setRequestHeader('X-CSRF-Token', token);
}