远程表格:真正的authenticity_token消失

时间:2019-10-31 13:45:52

标签: ruby-on-rails authenticity-token

如果我将remote:true设置为true,则authenticity_token消失。我必须在表单中添加authenticity_token:true吗?缓存呢?如果我缓存表单,则必须添加authenticity_token:是吗?是否存在authenticity_token缓存的问题?谢谢

1 个答案:

答案 0 :(得分:0)

您是否在应用中使用jquery-rails gem?这会将CSRF令牌自动添加到remote: true AJAX表单提交中:

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);
}