Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/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 错误重定向后不会显示闪存消息_Ruby On Rails_Ruby On Rails 3_Spree - Fatal编程技术网

Ruby on rails 错误重定向后不会显示闪存消息

Ruby on rails 错误重定向后不会显示闪存消息,ruby-on-rails,ruby-on-rails-3,spree,Ruby On Rails,Ruby On Rails 3,Spree,我有一个运行在Rails 3.2上的老式Spree 2.0在线商店,我正试图使用更干净的错误处理来定制它 config.exceptions_app = self.routes 在我的config/application.rb中 出于调试的目的,我已转到 config.consider_all_requests_local = false 在my config/environments/development.rb中 在my routes.rb中,我有: match '/404', to:

我有一个运行在Rails 3.2上的老式Spree 2.0在线商店,我正试图使用更干净的错误处理来定制它

config.exceptions_app = self.routes
在我的config/application.rb中

出于调试的目的,我已转到

config.consider_all_requests_local = false
在my config/environments/development.rb中

在my routes.rb中,我有:

match '/404', to: 'errors#file_not_found'
在我的控制器中,我有:

def file_not_found
  flash[:error] =  'The page you requested could not be found.'
  flash.keep
  redirect_to :back
rescue ActionController::RedirectBackError
  flash[:error] =  'The page you requested could not be found.'
  flash.keep
  redirect_to '/'
end
我尝试了几种不同的方法,包括在示例中描述的方法,但结果总是,如果我特别转到localhost:3000/404,flash消息有效,但是如果我转到一些不存在的URL,例如localhost:3000/asdfasdf,则flash消息无效

在app/views/spree/layouts中,我有spree_application.html.erb,我有

<%= flash_messages %>

are alert are are alert are are are are are are are alert are WARE SHOW flash[:alert]=找不到您请求的页面。我尝试显示哪种类型的闪存消息没有任何区别。它们只有在我显式键入/404路径时才会显示。您可能需要包含帮助程序在布局中包含此代码段。我想知道它是否与您当前在中间件堆栈中的位置有关。可能是因为flash已经提交,所以您正在进行的任何更改都会被丢弃?可能是因为/404在您直接访问该路线时匹配,所以它不会出现异常。
def flash_messages(opts = {})
  opts[:ignore_types] = [:commerce_tracking].concat(Array(opts[:ignore_types]) || [])

  flash.each do |msg_type, text|
    unless opts[:ignore_types].include?(msg_type)
      concat(content_tag :div, text, class: "flash #{msg_type}")
    end
  end
  nil
end