Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#2129

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:

/app/controllers/subdir1/foo_controller.rb

should be able to be accessed by

/foo/index

rather than

/subdir1/foo/index

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.

Reported by Ranjeet Smith · March 4th, 2009 @ 07:29 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Ranjeet Smith
    Ranjeet Smith

    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.

    March 4th, 2009 @ 07:57 PM

  2. Matt Jones
    Matt Jones

    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.

    March 4th, 2009 @ 10:52 PM

  3. Zyclops
    Zyclops

    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? }
    

    May 20th, 2009 @ 01:18 AM

  4. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:53 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:53 PM