Controllers More Than One Sub-Directory Deep?

Does anyone know how to make Rails aware of controllers that might
exist in directories that exist deeper than one level under the
app/controllers directory? I initially figured just adding additional
scope information might do the trik (i.e. Tabs::Admin::OneController
or Admin::Tabs::OneController), but that does not seem to work.

I’m guessing that I can just manually add these directories to the
environment load path, but I just wanted to make sure there wasn’t a
more elegant way of getting this to work. Thanks.


DeLynn B.
[email protected]

can’t you just create a controller like /script/generate controller
somedir/someotherder/somecontroller

Unless you have a really large, complex app, you might not want to do
this. It’s obviously tempting to put admin controllers in a
controllers/admin directory, the corresponding views in
views/admin/controllername and so on, but you may later find that an
engine or plugin you want to use won’t play well with this.

I tried it about a month ago not because my codebase was espcially big,
but because I was going to have authentication handled by the HTTP
server instead of by Rails and that’s the sensible way to organize code
around auth realms when you’re doing it with the webserver config. But
then I went with a much easier and powerful auth scheme using one of the
half dozen or so available plugins to handle authentication and
attribute-level model security in Rails instead. It crapped out on the
subdirectories and namespacing. It took me twenty minutes to scrap the
subdirectories, edit my models and controllers to flatten the namespace
and I haven’t looked back. I’m sure there are quite a few other plugins
and other useful components out there that don’t play well with
namespaced and subdirectoried view and controller directories.

DeLynn B. wrote:

Does anyone know how to make Rails aware of controllers that might
exist in directories that exist deeper than one level under the
app/controllers directory? I initially figured just adding additional
scope information might do the trik (i.e. Tabs::Admin::OneController
or Admin::Tabs::OneController), but that does not seem to work.

I’m guessing that I can just manually add these directories to the
environment load path, but I just wanted to make sure there wasn’t a
more elegant way of getting this to work. Thanks.


DeLynn B.
[email protected]
http://www.delynnberry.com

can’t you just create a controller like /script/generate controller
somedir/someotherder/somecontroller

You know what, I thought the same thing (and even tried it). Then
after seeing your email, I decided to try it again with a new Rails
application, and everything worked as expected! This confused me quite
a bit, and figured I had just done something incorrect in my original
application. So, I copied the controllers from the new application to
my existing application, but it still didn’t work.

Confused as to why this might be happening, I started duplicating as
much of my existing application to this newly created application
trying to find the point where things broke. What I discovered was
that everything worked right up to the point where I drop in Edge
Rails to get the 1.1 goodness that’s included there.

So now my question is, what has changed in 1.1 that would cause these
problems? I have detailed my specific application layout below.

app/controllers
base_controller.rb (Base < AC)
/admin
base_controller.rb (Admin::Base < Base)
location_controller.rb (Admin::LocationController <
Admin::BaseController)
/tabs
details_controller.rb (Admin::Tabs::DetailsController <
Admin::LocationController

The error I get when trying to navigate to /admin/tabs/details is
“uninitialized constant Admin::LocationController”. Here is the stack
trace that is generated:

#{RAILS_ROOT}/vendor/rails/activesupport/lib/active_support/dependencies.rb:106:in
`const_missing’

#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:236:in
`traverse_to_controller’

generated/routing/recognition.rb:46:in `eval’

generated/routing/recognition.rb:46:in `recognize_path’

I’m going to start digging around the 1.1 source and see what has
changed since 1.0 in the files listed above. Thanks.


DeLynn B.
[email protected]

Hi,
I think I ran into the same problem. I have my models in subdirectories
and as long as i reference models within the same subdirectory,
everything seems to work. As soon as I traverse directories, it breaks
with the “uninitialized constant” error (also see my post from today
regarding this).

Regards
Juergen