错误重定向后不显示Flash消息

时间:2015-03-05 10:42:15

标签: 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

在我的config / environments / development.rb

在我的routes.rb中我有:

match '/404', to: 'errors#file_not_found'

在我的errors_controller中我有:

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

我尝试了几种不同的方法,包括http://api.rubyonrails.org/classes/ActionController/Redirecting.html中的示例中描述的方法,但结果是,如果我专门访问localhost:3000/404,则flash消息有效,但不起作用如果我去一些不存在的URL,例如localhost:3000 / asdfasdf。

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

<%= flash_messages %>

反过来在/ spree_core-2.0.10 / app / helpers / spree / base_helper.rb中定义

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

0 个答案:

没有答案
相关问题