From f15be4b92add90f2e614ee1796932cd153587fdc Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 15 Mar 2013 17:35:32 +0400 Subject: [PATCH] #23: return json response at RoutingError --- app/controllers/application_controller.rb | 6 +++--- config/routes.rb | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0107fa98d..4948f5e79 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,10 +18,9 @@ class ApplicationController < ActionController::Base helper_method :get_owner unless Rails.env.development? - rescue_from Exception, :with => :render_500 rescue_from ActiveRecord::RecordNotFound, - ActionController::RoutingError, + # ActionController::RoutingError, # see: config/routes.rb: ActionController::UnknownController, AbstractController::ActionNotFound, :with => :render_404 end @@ -32,12 +31,13 @@ class ApplicationController < ActionController::Base rescue_from Grit::NoSuchPathError, :with => :not_found - protected def render_404 render_error 404 end + protected + def render_500(e) #check for exceptions Airbrake ignores by default and exclude them from manual Airbrake notification if Rails.env.production? && !AIRBRAKE_IGNORE.include?(e.class) diff --git a/config/routes.rb b/config/routes.rb index f564b379a..4d5e5c11c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -343,4 +343,9 @@ Rosa::Application.routes.draw do get '/' => 'groups/profile#show', :as => :group end end + + # As of Rails 3.0.1, using rescue_from in your ApplicationController to + # recover from a routing error is broken! + # see: https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror + match '*a', :to => 'application#render_404' end