【问题标题】:Form remote: true authenticity_token disappear表单远程:trueauthentity_token 消失
【发布时间】:2019-10-31 13:45:52
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails authenticity-token


    【解决方案1】:

    您是否在应用中使用了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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多