私のプロダクションサーバでランダムなActionController::InvalidAuthenticityToken
エラーが発生します。 AJAXリクエストはありません。すべてのフォームはRailsヘルパーによって作成されます(したがって、authenticity_tokenで隠されたフィールドを含みます)。ランダムActionController :: InvalidAuthenticityToken
この問題はランダムな形でランダムに表示されます。
私のApplicationController
には、3210があります。それが問題なのでしょうか?私はこれを追加しました。なぜなら私のユーザーはしばしばブラウザで「戻る」をクリックして、キャッシュされた結果を望んでいないからです。
マイsession_store.rb初期化子は、次のようになります。それは私がtimeoutable
モジュールと1.hour
へのconfig.timeout_in
セットで工夫を使用するすべての違いを作る場合
Rails.application.config.session_store :cookie_store, key: '_myapp_session'
。
私はRails 5.0.1を使用しています。
application_controller.rb:そのあなたのbefore_actionうん
class ApplicationController < ActionController::Base
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :not_authorized
protect_from_forgery with: :exception
add_flash_types :success, :warning, :danger, :info
before_action :authenticate_user!
before_action :set_current_user
before_action :set_cache_headers
def after_sign_out_path_for(_user)
tasks_path
end
def not_authorized
flash[:warning] = 'You are not authorized to execute this action.'
redirect_to tasks_path
end
private
def set_current_user
User.current = current_user
end
def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
end
end
適切な解決策に見える場合は、許容可能とマークしてください。 –
いいえ、これは役に立ちません。 'ActionController :: InvalidAuthenticityToken'はまだ時々発生します。 – pmichna
あなたのレイアウトファイルに '<%= csrf_meta_tags%>'があるかどうかを調べることができますそれ以外の場合はアプリケーションコントローラコードも貼り付けることができますか? –