Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从ActionController营救时未显示闪存消息::InvalidAuthenticationToken_Ruby On Rails_Flash - Fatal编程技术网

Ruby on rails 从ActionController营救时未显示闪存消息::InvalidAuthenticationToken

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

看起来像是rails的一个bug,但我想确保在报告bug之前没有遗漏任何东西

我正试图用以下代码从应用程序控制器中的
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散列都是空白的。