Ruby on rails 从ActionController营救时未显示闪存消息::InvalidAuthenticationToken
看起来像是rails的一个bug,但我想确保在报告bug之前没有遗漏任何东西 我正试图用以下代码从应用程序控制器中的Ruby on rails 从ActionController营救时未显示闪存消息::InvalidAuthenticationToken,ruby-on-rails,flash,Ruby On Rails,Flash,看起来像是rails的一个bug,但我想确保在报告bug之前没有遗漏任何东西 我正试图用以下代码从应用程序控制器中的ActionController::InvalidAuthenticityToken中拯救: class ApplicationController < ActionController::Base protect_from_forgery with: :exception rescue_from ActionController::InvalidAuthentici
ActionController::InvalidAuthenticityToken
中拯救:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
rescue_from ActionController::InvalidAuthenticityToken, with: :show_errors
....
private
def show_errors
redirect_to root_path, alert: "Cookies are disabled"
end
end
class ApplicationController
重定向工作正常,但不会显示警报消息。新页面中的闪存哈希为空:#
应用程序控制器中没有可能影响哈希/导致另一个重定向的其他筛选器。日志仅显示预期的一个重定向
尝试了flash。保持[:alert]=..
和flash。现在[:alert]=..
;不走运
在两个不同的rails应用程序上获得此行为,一个使用4.2.0
,另一个使用4.1.6
试试看
def show_errors
flash[:error] = "Cookies are disabled"
redirect_to root_path
end
Andrew White解释了正在发生的事情: 因为flash依赖于会话,而会话依赖于 如果你想一想,曲奇饼是不会起作用的 它,:-) 我建议重定向到自定义url,或者在 触发消息显示的url
我正在按照建议重定向到自定义url。不起作用。正如我上面提到的,整个flash散列都是空白的。