提交 72cb0bf4 编写于 作者: J José Valim

Do not swallow controller loading errors unless required.

上级 01cd9d66
......@@ -19,12 +19,7 @@ def initialize(options = {})
def call(env)
params = env[PARAMETERS_KEY]
prepare_params!(params)
unless controller = controller(params)
return [404, {'X-Cascade' => 'pass'}, []]
end
controller.action(params[:action]).call(env)
controller(params).action(params[:action]).call(env)
end
def prepare_params!(params)
......@@ -39,14 +34,13 @@ def prepare_params!(params)
end
end
def controller(params)
def controller(params, swallow=false)
if params && params.has_key?(:controller)
controller = "#{params[:controller].camelize}Controller"
ActiveSupport::Inflector.constantize(controller)
end
rescue NameError => e
raise unless e.message.include?(controller)
nil
raise ActionController::RoutingError, e.message, e.backtrace unless swallow
end
private
......@@ -433,7 +427,7 @@ def recognize_path(path, environment = {})
req = Rack::Request.new(env)
@set.recognize(req) do |route, params|
dispatcher = route.app
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params)
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, true)
dispatcher.prepare_params!(params)
return params
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册