From 4793a2f5cdc07a5926e8399fd82a835c0dc0a023 Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Sun, 15 Jan 2006 11:28:55 +0000 Subject: Automatically discover layouts when a controller is namespaced. Closes #2199, #3424. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3423 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/layout.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 4b396bb0d4..baa035507d 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -174,11 +174,12 @@ module ActionController #:nodoc: private def inherited(child) inherited_without_layout(child) - child.layout(child.controller_name) unless layout_list.grep(/^#{child.controller_name}\.[a-z][0-9a-z]*$/).empty? + layout_match = child.name.underscore.sub(/_controller$/, '') + child.layout(layout_match) unless layout_list.grep(%r{layouts/#{layout_match}\.[a-z][0-9a-z]*$}).empty? end def layout_list - Dir.glob("#{template_root}/layouts/*.*").map { |layout| File.basename(layout) } + Dir.glob("#{template_root}/layouts/**/*") end def add_layout_conditions(conditions) @@ -202,8 +203,12 @@ module ActionController #:nodoc: when Proc then layout.call(self) when String then layout end - - active_layout.include?("/") ? active_layout : "layouts/#{active_layout}" if active_layout + + # Explicitly passed layout names with slashes are looked up relative to the template root, + # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative + # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from. + nested_controller = File.directory?(File.dirname(File.join(self.class.template_root, 'layouts', active_layout))) + active_layout.include?('/') && !nested_controller ? active_layout : "layouts/#{active_layout}" if active_layout end def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil) #:nodoc: -- cgit v1.2.3