An exception is raised if a layout is missing only if the layout is missing for all mimes

上级 01a4bc84
......@@ -140,6 +140,8 @@ def _default_layout(details, require_layout = false)
rescue NameError => e
raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
rescue ActionView::MissingTemplate
_find_by_parts(_layout({}), {})
end
end
......
......@@ -176,7 +176,7 @@ def _determine_template(options)
super
return if (options.key?(:text) || options.key?(:inline) || options.key?(:partial)) && !options.key?(:layout)
layout = options.key?(:layout) ? options[:layout] : :none
layout = options.key?(:layout) ? options[:layout] : :default
options[:_layout] = _layout_for_option(layout, options[:_template].details)
end
......@@ -184,7 +184,7 @@ def _layout_for_option(name, details)
case name
when String then _layout_for_name(name, details)
when true then _default_layout(details, true)
when :none then _default_layout(details, false)
when :default then _default_layout(details, false)
when false, nil then nil
else
raise ArgumentError,
......
......@@ -124,8 +124,8 @@ def custom(mime_type, &block)
@controller.formats = [mime_type.to_sym]
end
@controller.content_type = mime_type
@controller.template.formats = [mime_type.to_sym]
@response.content_type = mime_type
block_given? ? block.call : @controller.send(:render, :action => @controller.action_name)
end
......
......@@ -467,14 +467,6 @@ def test_format_with_custom_response_type_and_request_headers
assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
assert_equal "text/html", @response.content_type
end
def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present
get :iphone_with_html_response_type_without_layout
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
@request.accept = "text/iphone"
assert_raise(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
end
end
class AbstractPostController < ActionController::Base
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册