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

Merged
merged 1 commit into from May 21, 2012

Conversation

Projects
None yet
5 participants
Contributor

trek commented Aug 16, 2011

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 Aug 22, 2011

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 Aug 22, 2011

Contributor

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

Contributor

isaacsanders commented Apr 28, 2012

@trek Is this still an issue?

Contributor

trek commented May 3, 2012

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

@tenderlove tenderlove added a commit that referenced this pull request May 21, 2012

@tenderlove tenderlove Merge pull request #2549 from trek/RoutingErrorForMissingControllers
When a route references a missing controller, raise ActionController::RoutingError with clearer message
513a052

@tenderlove tenderlove merged commit 513a052 into rails:master May 21, 2012

trek deleted the trek:RoutingErrorForMissingControllers branch May 22, 2013

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