I have an oldish Spree 2.0 online shop running on Rails 3.2, that I'm trying to customize with cleaner error handling, using
config.exceptions_app = self.routes
in my config/application.rb.
For debugging purposes I have turned
config.consider_all_requests_local = false
in my config/environments/development.rb
in my routes.rb I have:
match '/404', to: 'errors#file_not_found'
in my errors_controller I have:
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
I have tried several different ways of doing this, including the ones described in examples at http://ift.tt/1q8wGHM but always the result is, the flash message works if I specifically go to localhost:3000/404, but does not work if I go to some nonexistent URL, such as localhost:3000/asdfasdf.
In app/views/spree/layouts I have spree_application.html.erb, where I have
<%= flash_messages %>
which in turn is defined in/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
Aucun commentaire:
Enregistrer un commentaire