Skip to content

Commit c5ae44d

Browse files
committed
Alias field_set_tag helper to fieldset_tag
The [field_set_tag][] renders a `<fieldset>` element. At times, the desire to render a `fieldset` results in calling `fieldset_tag`, only to be surprised by a `NoMethodError`. Originally, the method's name was `fieldset_tag` helper (defined in [0e6c8e5][] in 2007), but was renamed in [73c7083][] (3 days later). This commit aliases `field_set_tag` to `fieldset_tag` so that both are available. Additionally, defines the method so that it utilizes the [content_tag][] so that it isn't responsible for manually managing the closing (`</fieldset>`) of the opening `<fieldset>` tag. [field_set_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_set_tag [0e6c8e5]: rails@0e6c8e5 [73c7083]: rails@73c7083 [content_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag
1 parent b3b230c commit c5ae44d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

actionview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Alias `field_set_tag` helper to `fieldset_tag` to match `<fieldset>` element
2+
3+
*Sean Doyle*
4+
15
* Deprecate passing content to void elements when using `tag.br` type tag builders.
26

37
*Hartley McGuire*

actionview/lib/action_view/helpers/form_tag_helper.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,13 @@ def image_submit_tag(source, options = {})
675675
# <% end %>
676676
# # => <fieldset class="format"><p><input id="name" name="name" type="text" /></p></fieldset>
677677
def field_set_tag(legend = nil, options = nil, &block)
678-
output = tag(:fieldset, options, true)
679-
output.safe_concat(content_tag("legend", legend)) unless legend.blank?
680-
output.concat(capture(&block)) if block_given?
681-
output.safe_concat("</fieldset>")
678+
content = []
679+
content << content_tag("legend", legend) unless legend.blank?
680+
content << capture(&block) if block_given?
681+
682+
content_tag(:fieldset, safe_join(content), options)
682683
end
684+
alias_method :fieldset_tag, :field_set_tag
683685

684686
# Creates a text field of type "color".
685687
#

actionview/test/template/form_tag_helper_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ def test_field_set_tag_in_erb
925925
expected = %(<fieldset class="format">Hello world!</fieldset>)
926926
assert_dom_equal expected, output_buffer
927927

928+
output_buffer = render_erb("<%= fieldset_tag('', :class => 'format') do %>Hello world!<% end %>")
929+
930+
expected = %(<fieldset class="format">Hello world!</fieldset>)
931+
assert_dom_equal expected, output_buffer
932+
928933
output_buffer = render_erb("<%= field_set_tag %>")
929934

930935
expected = %(<fieldset></fieldset>)

0 commit comments

Comments
 (0)