Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10926 (reopened defect)

Opened 1 year ago

Last modified 1 year ago

Routing not consistent for controllers grouped in modules

Reported by: bennette_harris Assigned to: core
Priority: high Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: route controller module
Cc:

Description

The following command sequence is replicable on Fedora 7/ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]/Rails 2.0.2:

$ rails temp
  <output snipped>
$ cd temp
$ ./script/generate controller a
  <output snipped>
$ ./script/generate controller a/temp
  <output snipped>
$ ./script/generate controller b
  <output snipped>
$ ./script/generate controller b/temp
  <output snipped>
$ ./script/console
Loading development environment (Rails 2.0.2)
>> rs = ActionController::Routing::Routes
  <output snipped>
>> rs.recognize_path "/a/temp"
=> {:action=>"temp", :controller=>"a"}
>> rs.recognize_path "/b/temp"
=> {:action=>"index", :controller=>"b/temp"}
>> quit

I cannot see why Rails routes /a/temp and /b/temp differently. Rails 1.2.4 on another system correctly routes both of these to the */temp controller with :action=>index. In actual practice, I was using modules named "admin" and "welcome" - the "admin"-prefixed routes worked correctly, but the "welcome"-prefixed routes did not.

Attachments

posible_controllers_dir_load_fix.diff (2.0 kB) - added by maxs on 02/03/08 03:42:08.
Controller paths array is sorted now before inferring possible controller names

Change History

02/01/08 17:11:57 changed by maxs

When Routing.possible_controllers method infers possible controllers using Dir.glob, it doesn't load controller paths in expected order for processing. So when the controller segment is build, it ends up with bad pattern.

In the above mentioned case it would be something like (b|b\/temp|a\/temp|a) which will always hit the 'b' and never 'b/temp'. Sorting controller paths before processing solves the problem since:

>> "/" <=> "_"
=> -1

and possible_controllers array will be in correct order. resulting in correct regexp for segment (a\/temp|a|b\/temp|b)

02/03/08 03:01:43 changed by maxs

  • status changed from new to closed.
  • resolution set to untested.

FYI, i added admin_controller.rb zero sized fixture file to accommodate the test. For some reason it's not show in trac, but it's there.

02/03/08 03:18:43 changed by maxs

  • summary changed from routing not consistent for controllers grouped in modules to [PATCH] Routing not consistent for controllers grouped in modules.

02/03/08 03:42:08 changed by maxs

  • attachment posible_controllers_dir_load_fix.diff added.

Controller paths array is sorted now before inferring possible controller names

02/03/08 18:51:56 changed by maxs

You need to create the fixture manually.

$ touch actionpack/test/controller/controller_fixtures/app/controllers/admin_controller.rb

patch will not create it for you. may be this patch should be made with "diff -Naur" instead of "svn diff"?

02/04/08 21:52:12 changed by maxs

  • status changed from closed to reopened.
  • resolution deleted.

02/04/08 21:52:37 changed by maxs

  • summary changed from [PATCH] Routing not consistent for controllers grouped in modules to Routing not consistent for controllers grouped in modules.