Gracefully handling InvalidAuthenticityToken exceptions in Rails 4

前端 未结 3 1117
北恋
北恋 2021-02-04 02:39

I\'ve just upgraded an app from Rails 3 to Rails 4, and I\'m seeing a bunch of InvalidAuthenticityToken exceptions popping up. Digging in it looks like it is fairly common for o

3条回答
  •  醉话见心
    2021-02-04 02:58

    Answer by Durrell is perfectly alright, I am just providing an alternative way to write the same thing. This needs to go in ApplicationController.

    rescue_from ActionController::InvalidAuthenticityToken do |_exception|
      flash[:alert] = 'Please try again.'
      redirect_back fallback_location: root_path
    end
    

提交回复
热议问题