diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 557f8454be9265fdc16c9e7338cc25e83147890b..932e9e2f95f15a97400a9ce064d0ab4f6f0fabe8 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -576,12 +576,12 @@ def fields_for(record_or_name_or_array, *args, &block)
# label(:post, :terms) do
# 'Accept Terms.'
# end
- def label(object_name, method, content_or_options_with_block = nil, options = nil, &block)
+ def label(object_name, method, content_or_options = nil, options = nil, &block)
if block_given?
- options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
+ options = content_or_options if content_or_options.is_a?(Hash)
text = nil
else
- text = content_or_options_with_block
+ text = content_or_options
end
options ||= {}
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 9d15805d469a949e0d15d2fe166d8002e74139fb..2a3f826c15391f05de3aded156cb8ae352a22fd0 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -156,15 +156,12 @@ def text_field_tag(name, value = nil, options = {})
#
# label_tag 'name', nil, :class => 'small_label'
# # =>
- def label_tag(name = nil, content_or_options_with_block = nil, options = nil, &block)
- if block_given?
- options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
- end
-
+ def label_tag(name = nil, content_or_options = nil, options = nil, &block)
+ options = content_or_options if block_given? && content_or_options.is_a?(Hash)
options ||= {}
options.stringify_keys!
options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
- content_tag :label, content_or_options_with_block || name.to_s.humanize, options, &block
+ content_tag :label, content_or_options || name.to_s.humanize, options, &block
end
# Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 1e116c041f685cee6f1f33966d52f82cf9d8486f..1c095b621e37e771eb28ed207401f104858d1ea1 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -297,6 +297,11 @@ def test_label_tag_with_block_and_argument
assert_dom_equal('', output)
end
+ def test_label_tag_with_block_and_argument_and_options
+ output = label_tag("clock", :id => "label_clock") { "Grandfather" }
+ assert_dom_equal('', output)
+ end
+
def test_boolean_options
assert_dom_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)