aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-25 16:00:20 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-25 16:00:20 -0700
commita26033b4a620059dff2779bdc77024f3123cc44f (patch)
tree4311052c432f44d95960bc41038218a7fc0f211c /actionpack/lib/action_dispatch/routing
parent702965c1b724852afb08e93df64dd65dbcf762d4 (diff)
downloadrails-a26033b4a620059dff2779bdc77024f3123cc44f.tar.gz
rails-a26033b4a620059dff2779bdc77024f3123cc44f.tar.bz2
rails-a26033b4a620059dff2779bdc77024f3123cc44f.zip
always dispatch to controllers the same way
controllers should always go through the `action` class method so that their middleware is respected.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb18
2 files changed, 25 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index c3a9422ceb..1acfb2bfe8 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -283,12 +283,16 @@ module ActionDispatch
end
def app(blocks)
- if to.respond_to?(:call)
- Constraints.new(to, blocks, Constraints::CALL)
- elsif blocks.any?
- Constraints.new(dispatcher(defaults.key?(:controller)), blocks, Constraints::SERVE)
+ if to.is_a?(Class) && to < ActionController::Metal
+ Routing::RouteSet::StaticDispatcher.new to
else
- dispatcher(defaults.key?(:controller))
+ if to.respond_to?(:call)
+ Constraints.new(to, blocks, Constraints::CALL)
+ elsif blocks.any?
+ Constraints.new(dispatcher(defaults.key?(:controller)), blocks, Constraints::SERVE)
+ else
+ dispatcher(defaults.key?(:controller))
+ end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 065df09f8b..c026d0e2d9 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -28,8 +28,7 @@ module ActionDispatch
def serve(req)
params = req.path_parameters
- controller = req.controller_class
- dispatch(controller, params[:action], req)
+ dispatch(controller(req), params[:action], req)
rescue NameError => e
if @raise_on_name_error
raise ActionController::RoutingError, e.message, e.backtrace
@@ -40,11 +39,26 @@ module ActionDispatch
private
+ def controller(req)
+ req.controller_class
+ end
+
def dispatch(controller, action, req)
controller.action(action).call(req.env)
end
end
+ class StaticDispatcher < Dispatcher
+ def initialize(controller_class)
+ super(false)
+ @controller_class = controller_class
+ end
+
+ private
+
+ def controller(_); @controller_class; end
+ end
+
# A NamedRouteCollection instance is a collection of named routes, and also
# maintains an anonymous module that can be used to install helpers for the
# named routes.