Skip to content

Commit

Permalink
When a route references a missing controller, raise ActionController:…
Browse files Browse the repository at this point in the history
…:RoutingError with a clearer message
  • Loading branch information
trek committed Aug 16, 2011
1 parent 5902391 commit dde5b87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -556,9 +556,13 @@ def recognize_path(path, environment = {})
dispatcher = dispatcher.app
end

if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
dispatcher.prepare_params!(params)
return params
if dispatcher.is_a?(Dispatcher)
if dispatcher.controller(params, false)
dispatcher.prepare_params!(params)
return params
else
raise ActionController::RoutingError, "A route matches #{path.inspect}, but references missing controller: #{params[:controller].camelize}Controller"
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -902,6 +902,16 @@ def test_route_constraints_with_options_method_condition_is_valid
end
end

def test_route_error_with_missing_controller
set.draw do
get "/people" => "missing#index"
end

assert_raise(ActionController::RoutingError) {
set.recognize_path("/people", :method => :get)
}
end

def test_recognize_with_encoded_id_and_regex
set.draw do
match 'page/:id' => 'pages#show', :id => /[a-zA-Z0-9\+]+/
Expand Down

0 comments on commit dde5b87

Please sign in to comment.