提交 a16fa9ab 编写于 作者: D David Heinemeier Hansson

Allow code execution in case no variant has been set with variant.none

上级 76dae289
......@@ -196,9 +196,10 @@ def clear_respond_to
# Respond to variants in the action just like you respond to formats:
#
# respond_to do |format|
# format.html do |html|
# html.tablet # renders app/views/projects/show.html+tablet.erb
# html.phone { extra_setup; render ... }
# format.html do |variant|
# variant.tablet # renders app/views/projects/show.html+tablet.erb
# variant.phone { extra_setup; render ... }
# variant.none { special_setup } # executed only if there is no variant set
# end
# end
#
......@@ -465,7 +466,7 @@ def initialize(variant)
end
def method_missing(name)
yield if name == @variant
yield if name == @variant || (name == :none && @variant.nil?)
end
end
end
......
......@@ -166,6 +166,15 @@ def multiple_variants_for_format
end
end
def variant_plus_none_for_format
respond_to do |format|
format.html do |variant|
variant.phone { render text: "phone" }
variant.none { render text: "none" }
end
end
end
protected
def set_layout
case action_name
......@@ -544,4 +553,11 @@ def test_multiple_variants_for_format
assert_equal "text/html", @response.content_type
assert_equal "tablet", @response.body
end
def test_no_variant_in_variant_setup
get :variant_plus_none_for_format
assert_equal "text/html", @response.content_type
assert_equal "none", @response.body
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册