This project is archived and is in readonly mode.

#2129 ✓stale
Ranjeet Smith

Dispatcher interprets path separators in controller names as nested modules/namespaces whether you like it or not.

Reported by Ranjeet Smith | March 4th, 2009 @ 07:29 PM | in 3.x

It seems to be impossible to organize controllers into subdirectories without Rails assuming that this is being done out of some latent desire on the user's part to create additional namespaces. While I understand the utility of such a feature, there really should be an off switch for those of us who would like to use these subdirectories for purely organizational purposes and continue to have the controllers which they enclose behave as though they were at the root level.

For example:


should be able to be accessed by


rather than


in cases where "subdir1" has no relevance to the site's public presentation and therefore no reason to be displayed to the public.

I can certainly create dozens of routes to accomplish this without any trouble, but it would be much better if there were simply a way of specifying a default namespace for a generic catch-all route, or a way to tell the dispatcher to stop expecting to find Subdir1::FooController just because I made a folder.

Comments and changes to this ticket

  • Ranjeet Smith

    Ranjeet Smith March 4th, 2009 @ 07:57 PM

    I should add that in previous versions of Rails it was possible to simply append these subdirectories to config.load_paths and have their contents treated as regular, non-namespaced controllers. 2.3 breaks this capability.

  • Matt Jones

    Matt Jones March 4th, 2009 @ 10:52 PM

    I just tested this on 2.2.2, and it doesn't work unless both config.load_paths and config.controller_paths have the subdirectory added to them. Without the load_paths, the controller definition wasn't found; and without the controller_paths the route wouldn't resolve. Identical behavior on 2.3 edge.

    @Ranjeet - when (what version) did this work in the way you've described? Can you write a test that passes on 2.2.2 but not 2.3? Either a test or a sample app that demonstrates the behavior would be very helpful.

  • Zyclops

    Zyclops May 20th, 2009 @ 01:18 AM

    The following does the trick for me. I don't know whether this is worth building into rails?

    config.load_paths += Dir["#{RAILS_ROOT}/app/models/**/*"].find_all { |f| File.stat(f).directory? }
    config.load_paths += Dir["#{RAILS_ROOT}/app/controllers/**/*"].find_all { |f| File.stat(f).directory? }
    config.controller_paths += Dir["#{RAILS_ROOT}/app/controllers/**/*"].find_all { |f| File.stat(f).directory? }
  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:53 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:53 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket