diff options
author | Marcel Molina <marcel@vernix.org> | 2006-01-15 11:28:55 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-01-15 11:28:55 +0000 |
commit | 4793a2f5cdc07a5926e8399fd82a835c0dc0a023 (patch) | |
tree | 422a9724779a3ce0be13774eb8598b7a7e70a805 /actionpack/lib/action_controller | |
parent | a471e6b4d741c498439767237efad9838df44834 (diff) | |
download | rails-4793a2f5cdc07a5926e8399fd82a835c0dc0a023.tar.gz rails-4793a2f5cdc07a5926e8399fd82a835c0dc0a023.tar.bz2 rails-4793a2f5cdc07a5926e8399fd82a835c0dc0a023.zip |
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
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/layout.rb | 13 |
1 files changed, 9 insertions, 4 deletions
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: |