mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
fa54f58733
commit
702965c1b7
2 changed files with 14 additions and 9 deletions
|
@ -68,16 +68,23 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
PASS_NOT_FOUND = Class.new { # :nodoc:
|
||||||
|
def self.action(_); self; end
|
||||||
|
def self.call(_); [404, {'X-Cascade' => 'pass'}, []]; end
|
||||||
|
}
|
||||||
|
|
||||||
def controller_class
|
def controller_class
|
||||||
check_path_parameters!
|
check_path_parameters!
|
||||||
params = path_parameters
|
params = path_parameters
|
||||||
controller_param = params[:controller].underscore if params.key?(:controller)
|
|
||||||
params[:action] ||= 'index'
|
|
||||||
|
|
||||||
yield unless controller_param
|
if params.key?(:controller)
|
||||||
|
controller_param = params[:controller].underscore
|
||||||
const_name = "#{controller_param.camelize}Controller"
|
params[:action] ||= 'index'
|
||||||
ActiveSupport::Dependencies.constantize(const_name)
|
const_name = "#{controller_param.camelize}Controller"
|
||||||
|
ActiveSupport::Dependencies.constantize(const_name)
|
||||||
|
else
|
||||||
|
PASS_NOT_FOUND
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def key?(key)
|
def key?(key)
|
||||||
|
|
|
@ -28,9 +28,7 @@ module ActionDispatch
|
||||||
|
|
||||||
def serve(req)
|
def serve(req)
|
||||||
params = req.path_parameters
|
params = req.path_parameters
|
||||||
controller = req.controller_class do
|
controller = req.controller_class
|
||||||
return [404, {'X-Cascade' => 'pass'}, []]
|
|
||||||
end
|
|
||||||
dispatch(controller, params[:action], req)
|
dispatch(controller, params[:action], req)
|
||||||
rescue NameError => e
|
rescue NameError => e
|
||||||
if @raise_on_name_error
|
if @raise_on_name_error
|
||||||
|
|
Loading…
Reference in a new issue