From d3de3f4bcd05574d7c31a9df32f5377266b1f81d Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 5 Jun 2010 13:42:55 -0400 Subject: [PATCH] :to in routes should allow controller names [#4326 state:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 +++- actionpack/test/dispatch/routing_test.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8a8d21c..305c710 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -117,7 +117,9 @@ module ActionDispatch end def default_controller_and_action - if to.respond_to?(:call) + if to.respond_to?(:ancestors) && to.ancestors.include?(AbstractController::Base) + { :controller => to.name.gsub(/Controller/,'').underscore, :action => 'index' } + elsif to.respond_to?(:call) { } else defaults = case to diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 180889d..9e09af2 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1,6 +1,12 @@ require 'abstract_unit' require 'controller/fake_controllers' +class DashboardController < ApplicationController + def index + render :text => "dashboard#index" + end +end + class TestRoutingMapper < ActionDispatch::IntegrationTest SprocketsApp = lambda { |env| [200, {"Content-Type" => "text/html"}, ["javascripts"]] @@ -125,6 +131,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :comments, :except => :destroy end + match "dashboard_list", :to => DashboardController + resources :sheep match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp @@ -638,6 +646,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_routes_for_to_with_controller_name + with_test_routes do + get '/dashboard_list' + assert_equal 'dashboard#index', @response.body + end + end + def test_resource_routes_with_only_and_except with_test_routes do get '/posts' -- 1.6.5.2