![](/img/trans.png)
[英]ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): Rails 5
[英]Rails 6 - constant ActionController::InvalidAuthenticityToken
我正在修改 Rails 6 并且我不断在由 rails 生成的表单上获取 ActionController::InvalidAuthenticityToken,例如(实现 rails 教程书籍注册/登录流程)
<%= form_for(@user, url: 'signup') do |f| %>
<%= render 'partials/error_messages' %>
<%= f.label :name, "Nimi" %>
<%= f.text_field :name %>
<%= f.label :email, "E-mail" %>
<%= f.email_field :email %>
<%= f.label :password, "Parool" %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Korda parooli" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Loo konto", class: "button-green" %>
<% end %>
这发生在所有形式上,输出转储看起来像这样
应用程序.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Storebase - kaasaegsed e-poed!</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body class="bg-gray-100 text-gray-900">
<% flash.each do |message_type, message| %>
<div class="bg-blue-100 text-blue-500 flex items-center h-12 px-12 shadow-lg flash-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= debug(params) if Rails.env.development? %>
</body>
</html>
我该怎么办?
在一个控制器中看到了这一点,该控制器将 Devise 子类化以获取动作挂钩。 它只发生在:destroy
对我来说的行动上。
class MySessionsController < Devise::SessionsController
after_action :after_login, only: [:create]
after_action :after_logout, only: [:destroy]
private
def after_login
end
def after_logout
end
我没有看到在销毁时跳过身份验证的风险,因此在控制器中添加这一行为我解决了这个问题: skip_before_action :verify_authenticity_token, only:[:destroy]
。 ¯_(ツ)_/¯
这是 Rails6 升级引入的错误或功能吗? 是否存在跳过我看不到的安全风险? 任何见解将不胜感激:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.