mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow code execution in case no variant has been set with variant.none
This commit is contained in:
parent
76dae289ed
commit
a16fa9abfd
2 changed files with 21 additions and 4 deletions
|
@ -196,9 +196,10 @@ module ActionController #:nodoc:
|
||||||
# Respond to variants in the action just like you respond to formats:
|
# Respond to variants in the action just like you respond to formats:
|
||||||
#
|
#
|
||||||
# respond_to do |format|
|
# respond_to do |format|
|
||||||
# format.html do |html|
|
# format.html do |variant|
|
||||||
# html.tablet # renders app/views/projects/show.html+tablet.erb
|
# variant.tablet # renders app/views/projects/show.html+tablet.erb
|
||||||
# html.phone { extra_setup; render ... }
|
# variant.phone { extra_setup; render ... }
|
||||||
|
# variant.none { special_setup } # executed only if there is no variant set
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
@ -465,7 +466,7 @@ module ActionController #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(name)
|
def method_missing(name)
|
||||||
yield if name == @variant
|
yield if name == @variant || (name == :none && @variant.nil?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -166,6 +166,15 @@ class RespondToController < ActionController::Base
|
||||||
end
|
end
|
||||||
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
|
protected
|
||||||
def set_layout
|
def set_layout
|
||||||
case action_name
|
case action_name
|
||||||
|
@ -544,4 +553,11 @@ class RespondToControllerTest < ActionController::TestCase
|
||||||
assert_equal "text/html", @response.content_type
|
assert_equal "text/html", @response.content_type
|
||||||
assert_equal "tablet", @response.body
|
assert_equal "tablet", @response.body
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue