コンテキスト:Herokuでホストされ、約800人のユーザーがいる本番環境のRailsアプリ。
何らかの理由で、いくつかのユーザーがエラーを経験するのを見ました:
ActionController::InvalidAuthenticityToken
[GEM_ROOT]/gems/actionpack-5.1.4/lib/action_controller/metal/request_forgery_protection.rb:195
へのリクエストの場合POST /students/:id/registrations
。
これは断続的であり、エラーが発生するユーザーはほとんどいません。
クライアントはiPad上のSafari11.0です。
ApplicationController:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!, unless: :devise_controller?
before_action :restrict_from_students, unless: :devise_controller?
# ...
end
RegistrationsController:
class RegistrationsController < ApplicationController
skip_before_action :restrict_from_students, only: :create
# ...
end
これを引き起こすシナリオ(リクエストの再POST、認証タイムアウトだが送信、JSの欠如)はありますか?再現できないようです。
ゴム製のアヒルのおかげで、私は問題を再現しました。
ここでの解決策はrescue_from
、ユーザーをサインインページにリダイレクトするために使用することです。
ラバーダックありがとう!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加