Skip to content

Commit 6908a66

Browse files
authored
Merge pull request rails#50245 from seanpdoyle/field-id-field-name-docs
Action View Docs: `field_id` and `field_name` examples [ci skip]
2 parents c5d519f + 9de8f1a commit 6908a66

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

actionview/lib/action_view/helpers/form_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,12 +1780,12 @@ def field_id(method, *suffixes, namespace: @options[:namespace], index: @options
17801780
#
17811781
# <%= form_for @post do |f| %>
17821782
# <%= f.text_field :title, name: f.field_name(:title, :subtitle) %>
1783-
# <%# => <input type="text" name="post[title][subtitle]">
1783+
# <%# => <input type="text" name="post[title][subtitle]"> %>
17841784
# <% end %>
17851785
#
17861786
# <%= form_for @post do |f| %>
17871787
# <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
1788-
# <%# => <input type="text" name="post[tag][]">
1788+
# <%# => <input type="text" name="post[tag][]"> %>
17891789
# <% end %>
17901790
#
17911791
def field_name(method, *methods, multiple: false, index: @options[:index])

actionview/lib/action_view/helpers/form_tag_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ def form_tag(url_for_options = {}, options = {}, &block)
9191
# attribute name.
9292
#
9393
# <%= label_tag :post, :title %>
94-
# <%= text_field_tag :post, :title, aria: { describedby: field_id(:post, :title, :error) } %>
94+
# <%= text_field :post, :title, aria: { describedby: field_id(:post, :title, :error) } %>
9595
# <%= tag.span("is blank", id: field_id(:post, :title, :error) %>
9696
#
9797
# In the example above, the <tt><input type="text"></tt> element built by
98-
# the call to <tt>text_field_tag</tt> declares an
98+
# the call to <tt>text_field</tt> declares an
9999
# <tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
100100
# element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
101101
# case).
@@ -123,11 +123,11 @@ def field_id(object_name, method_name, *suffixes, index: nil, namespace: nil)
123123
# Return the value generated by the <tt>FormBuilder</tt> for the given
124124
# attribute name.
125125
#
126-
# <%= text_field_tag :post, :title, name: field_name(:post, :title, :subtitle) %>
127-
# <%# => <input type="text" name="post[title][subtitle]">
126+
# <%= text_field :post, :title, name: field_name(:post, :title, :subtitle) %>
127+
# <%# => <input type="text" name="post[title][subtitle]"> %>
128128
#
129-
# <%= text_field_tag :post, :tag, name: field_name(:post, :tag, multiple: true) %>
130-
# <%# => <input type="text" name="post[tag][]">
129+
# <%= text_field :post, :tag, name: field_name(:post, :tag, multiple: true) %>
130+
# <%# => <input type="text" name="post[tag][]"> %>
131131
#
132132
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
133133
names = method_names.map! { |name| "[#{name}]" }.join

0 commit comments

Comments
 (0)