aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/general_controller.rb6
-rw-r--r--config/application.rb5
3 files changed, 14 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b8bdc403c..62479f200 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -12,6 +12,8 @@ require 'open-uri'
class ApplicationController < ActionController::Base
class PermissionDenied < StandardError
end
+ class RouteNotFound < StandardError
+ end
# assign our own handler method for non-local exceptions
rescue_from Exception, :with => :render_exception
@@ -128,7 +130,7 @@ class ApplicationController < ActionController::Base
@exception_class = exception.class.to_s
@exception_message = exception.message
case exception
- when ActiveRecord::RecordNotFound
+ when ActiveRecord::RecordNotFound, RouteNotFound
@status = 404
when PermissionDenied
@status = 403
@@ -173,6 +175,7 @@ class ApplicationController < ActionController::Base
render :template => "general/exception_caught", :status => @status
end
+
# FIXME: This was disabled during the Rails 3 upgrade as this is now handled by Rack
# # For development sites.
# alias original_rescue_action_locally rescue_action_locally
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 0df685829..9d0f91dda 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -222,5 +222,11 @@ class GeneralController < ApplicationController
@locale = self.locale_from_params()
render(:layout => false, :content_type => 'text/css')
end
+
+ # Handle requests for non-existent URLs - will be handled by ApplicationController::render_exception
+ def not_found
+ raise RouteNotFound
+ end
+
end
diff --git a/config/application.rb b/config/application.rb
index f5b525a36..92fd30685 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -55,8 +55,11 @@ module Alaveteli
# will be in this time zone
config.time_zone = ::AlaveteliConfiguration::time_zone
- config.after_initialize do
+ config.after_initialize do |app|
require 'routing_filters.rb'
+ # Add a catch-all route to force routing errors to be handled by the application,
+ # rather than by middleware.
+ app.routes.append{ match '*path', :to => 'general#not_found' }
end
config.autoload_paths << "#{Rails.root.to_s}/lib/mail_handler"