2014-06-27 25 views

回答

1

你會是最好鉤住config.exceptions_app中間件鉤:

設置由ShowException顯示 中間件調用時發生異常的異常應用。默認爲 ActionDispatch :: PublicExceptions.new(Rails.public_path)。

-

exceptions_app

written a gem about this,並且有它如何可以有效地使用一些非常nice demonstrations,我建議你做這樣的事情:

#config/application.rb 
config.exceptions_app = ->(env) { ApplicationController.action(:exception).call(env) } 

#app/controllers/application_controller.rb 
Class ApplicationController < ActionController::Base 
    def exception 
     # your code here 
    end 
end 

我不知道你如何使它有條件(IE只捕獲「找不到」的例外),但上述會成爲一個肯定的起點!

1

如果404就是你以後被失蹤,我會建議使用rescue_from,在應用程序控制器的代碼看起來類似原因造成的:

rescue_from ActiveRecord::RecordNotFound, with: :not_found 

def not_found 
# log anything in the request 
end 
相關問題