Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a route references a missing controller, raise ActionController::RoutingError with clearer message #2549

Merged
merged 1 commit into from
May 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Original file line number Diff line number Diff line change
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this line up? It's awfully long.

end
end
end

Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/routing_test.rb
Original file line number Diff line number Diff line change
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