Myself

仕事、プライベート、その他色々
Feb 15
Permalink

rails exception

railsで例外が起きたときはrescue_action_in_publicをオーバーライドすれば、

例外毎に好きな処理かけるわけですが、application.rbなんかに書いてると、

controller読み込む前で例外起きたら取得できないので、

lib/あたりに、突っ込んでおいて environment.rbあたりで読み込んでおいた。

lib/error_handle.rb

class ActionController::Base
  def rescue_action_in_public(exception)
    case exception
    when ::ActionController::RoutingError, ::ActionController::UnknownAction
    else
      render_optional_error_file response_code_for_rescue(exception)
    end
  end
end

こんな感じか~

Comments (View)
blog comments powered by Disqus