Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

5 participants

@trek

When a route points to an unimplemented controller, ActionController::RoutingError is raised with a message No route matches ..., although the route does exist and match.

MyApp::Application.routes.draw do
  root :to => 'welcome#index'
end

and example spec that fails with misleading error:

describe "welcome" do
  it "GET / -> welcome#show" do
    { :get => "/" }.should route_to(:controller => "welcome", :action => 'index')
  end
end

This is a pull request version of #2546

@dasch dasch commented on the diff
actionpack/lib/action_dispatch/routing/route_set.rb
@@ -556,9 +556,13 @@ module ActionDispatch
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"
@dasch
dasch added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@isaacsanders

@trek Is this still an issue?

@trek

Just tested against HEAD and yes, it's still an issue.

@tenderlove tenderlove merged commit 513a052 into rails:master
@trek trek deleted the trek:RoutingErrorForMissingControllers branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 16, 2011
  1. @trek

    When a route references a missing controller, raise ActionController:…

    trek authored
    …:RoutingError with a clearer message
This page is out of date. Refresh to see the latest.
View
10 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -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"
@dasch
dasch added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ end
end
end
View
10 actionpack/test/controller/routing_test.rb
@@ -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\+]+/
Something went wrong with that request. Please try again.