From 99975e742eb2636cd814f2c9de21f4bd3c3dbbc7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 7 Dec 2013 16:32:38 -0800 Subject: [PATCH] Variants can be declared without a block to signify their presence in the controller --- actionpack/lib/action_controller/metal/mime_responds.rb | 4 +++- actionpack/test/controller/mime/respond_to_test.rb | 2 +- .../fixtures/respond_to/variant_plus_none_for_format.html.erb | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 actionpack/test/fixtures/respond_to/variant_plus_none_for_format.html.erb diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 4993583c299e4..b47abb8b8c225 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -466,7 +466,9 @@ def initialize(variant) end def method_missing(name) - yield if name == @variant || (name == :none && @variant.nil?) + if block_given? + yield if name == @variant || (name == :none && @variant.nil?) + end end end end diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index cd9304336027d..c258bbec06cbd 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -170,7 +170,7 @@ def variant_plus_none_for_format respond_to do |format| format.html do |variant| variant.phone { render text: "phone" } - variant.none { render text: "none" } + variant.none end end end diff --git a/actionpack/test/fixtures/respond_to/variant_plus_none_for_format.html.erb b/actionpack/test/fixtures/respond_to/variant_plus_none_for_format.html.erb new file mode 100644 index 0000000000000..c86c3f3551ecf --- /dev/null +++ b/actionpack/test/fixtures/respond_to/variant_plus_none_for_format.html.erb @@ -0,0 +1 @@ +none \ No newline at end of file