提交 a26033b4 编写于 作者: A Aaron Patterson

always dispatch to controllers the same way

controllers should always go through the `action` class method so that
their middleware is respected.
上级 702965c1
......@@ -247,6 +247,7 @@ def self.call(env)
req = ActionDispatch::Request.new env
action(req.path_parameters[:action]).call(env)
end
class << self; deprecate :call; end
# Returns a Rack endpoint for the given action name.
def self.action(name)
......
......@@ -283,6 +283,9 @@ def normalize_defaults(options)
end
def app(blocks)
if to.is_a?(Class) && to < ActionController::Metal
Routing::RouteSet::StaticDispatcher.new to
else
if to.respond_to?(:call)
Constraints.new(to, blocks, Constraints::CALL)
elsif blocks.any?
......@@ -291,6 +294,7 @@ def app(blocks)
dispatcher(defaults.key?(:controller))
end
end
end
def check_controller_and_action(path_params, controller, action)
hash = check_part(:controller, controller, path_params, {}) do |part|
......
......@@ -28,8 +28,7 @@ def dispatcher?; true; end
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 @@ def serve(req)
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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册