Re: Re: Location of Nested Controller Layout Files

Duane Johnson
Sun, 05 Feb 2006 21:28:21 -0000

On Feb 3, 2006, at 4:19 PM, DeLynn Berry wrote:

> Another quick observation.
>
> Would it also make sense for a Admin::UsersController to first look
> for a layouts/admin/application.rhtml file first before looking for
> the layouts/admin/users.rhtml file?
>
> This would allow one to easily create different layouts for the
> different sub-sections of an application without having to specify the
> layout in the controller or creating a seperate layout file for every
> controller in their "admin" section.
>

I think that may cause a little confusion if there''s a special check
for the ''application'' layout within subdirectories.  I suggest
making  a BaseController from which other controllers inherit in that
directory... e.g.

class Admin::BaseController < ApplicationController
   layout ''admin''
end

class Admin::UsersController < Admin::BaseController
   # etc.
end

This has worked well for me in the past where I''ve needed some simple
but shared functionality within a "module" or group of controllers.

I like your previous suggestion of removing the extraneous
"controller" directory from the ''layouts'' directory.
I didn''t even
know that was the current requirement.

Just thinking out loud... the same principle would make the auto-
inclusion of javascripts and stylesheets more sensible also--
something that I''ve been trying to find a solution for within my
bundled_resource plugin.  For example: public/javascripts/admin/
new.js, or public/stylesheets/admin/base.css.  Of course, this only
works with assets and resources that assume quite a bit about the
app''s controllers and views.

Duane Johnson
(canadaduane)