提交 702965c1 编写于 作者: A Aaron Patterson

always return a controller class from the `controller_class` method

now the caller can just treat it like a regular controller even though
it will return a 404
上级 fa54f587
......@@ -68,16 +68,23 @@ def check_path_parameters!
end
end
PASS_NOT_FOUND = Class.new { # :nodoc:
def self.action(_); self; end
def self.call(_); [404, {'X-Cascade' => 'pass'}, []]; end
}
def controller_class
check_path_parameters!
params = path_parameters
controller_param = params[:controller].underscore if params.key?(:controller)
params[:action] ||= 'index'
yield unless controller_param
const_name = "#{controller_param.camelize}Controller"
ActiveSupport::Dependencies.constantize(const_name)
if params.key?(:controller)
controller_param = params[:controller].underscore
params[:action] ||= 'index'
const_name = "#{controller_param.camelize}Controller"
ActiveSupport::Dependencies.constantize(const_name)
else
PASS_NOT_FOUND
end
end
def key?(key)
......
......@@ -28,9 +28,7 @@ def dispatcher?; true; end
def serve(req)
params = req.path_parameters
controller = req.controller_class do
return [404, {'X-Cascade' => 'pass'}, []]
end
controller = req.controller_class
dispatch(controller, params[:action], req)
rescue NameError => e
if @raise_on_name_error
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册