From 95c9718118bc0342ddb320f23b5e0a17fb12b7ad Mon Sep 17 00:00:00 2001 From: Yehuda Katz and Carl Lerche Date: Tue, 7 Apr 2009 15:54:02 -0700 Subject: Layouts work in AbstractController. Add support for the rspec runner for T::U --- .../lib/action_controller/abstract/layouts.rb | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller/abstract') diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb index 2680283151..1990941916 100644 --- a/actionpack/lib/action_controller/abstract/layouts.rb +++ b/actionpack/lib/action_controller/abstract/layouts.rb @@ -13,6 +13,10 @@ module AbstractController _write_layout_method end + def _implied_layout_name + name.underscore + end + def _write_layout_method case @_layout when String @@ -24,8 +28,8 @@ module AbstractController else self.class_eval %{ def _layout - if view_paths.find_by_parts?("#{controller_path}", formats, "layouts") - "#{controller_path}" + if view_paths.find_by_parts?("#{_implied_layout_name}", formats, "layouts") + "#{_implied_layout_name}" else super end @@ -45,9 +49,12 @@ module AbstractController def _layout_for_option(name) case name - when String then _layout_for_name(name) - when true then _default_layout(true) - when false then nil + when String then _layout_for_name(name) + when true then _default_layout(true) + when false, nil then nil + else + raise ArgumentError, + "String, true, or false, expected for `layout'; you passed #{name.inspect}" end end @@ -56,7 +63,12 @@ module AbstractController end def _default_layout(require_layout = false) - _layout_for_option(_layout) + begin + _layout_for_option(_layout) + rescue NameError => e + raise NoMethodError, + "You specified #{@_layout.inspect} as the layout, but no such method was found" + end end end end \ No newline at end of file -- cgit v1.2.3