Skip to content

Commit 022e243

Browse files
byrootheka1024
authored andcommitted
Rename check_box in checkbox
But add aliases for backward compatibility. Fix: rails#52430
1 parent 1b3f4a2 commit 022e243

17 files changed

+292
-283
lines changed

actionview/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
* Rename `check_box*` methods into `checkbox*`.
2+
3+
Old names are still available as aliases.
4+
5+
*Jean Boussier*
16

27
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actionview/CHANGELOG.md) for previous changes.

actionview/lib/action_view/helpers/form_helper.rb

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ module FormHelper
133133
# First name: <%= f.text_field :first_name %><br />
134134
# Last name : <%= f.text_field :last_name %><br />
135135
# Biography : <%= f.text_area :biography %><br />
136-
# Admin? : <%= f.check_box :admin %><br />
136+
# Admin? : <%= f.checkbox :admin %><br />
137137
# <%= f.submit %>
138138
# <% end %>
139139
#
@@ -200,7 +200,7 @@ module FormHelper
200200
# First name: <%= f.text_field :first_name %>
201201
# Last name : <%= f.text_field :last_name %>
202202
# Biography : <%= text_area :person, :biography %>
203-
# Admin? : <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
203+
# Admin? : <%= checkbox_tag "person[admin]", "1", @person.company.admin? %>
204204
# <%= f.submit %>
205205
# <% end %>
206206
#
@@ -390,7 +390,7 @@ module FormHelper
390390
# <%= f.text_field :first_name %>
391391
# <%= f.text_field :last_name %>
392392
# <%= f.text_area :biography %>
393-
# <%= f.check_box :admin %>
393+
# <%= f.checkbox :admin %>
394394
# <%= f.submit %>
395395
# <% end %>
396396
#
@@ -669,7 +669,7 @@ def apply_form_for_options!(object, options) # :nodoc:
669669
# <%= form.text_field :last_name %>
670670
#
671671
# <%= text_area :person, :biography %>
672-
# <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
672+
# <%= checkbox_tag "person[admin]", "1", @person.company.admin? %>
673673
#
674674
# <%= form.submit %>
675675
# <% end %>
@@ -731,7 +731,7 @@ def apply_form_for_options!(object, options) # :nodoc:
731731
# <%= form.text_field :first_name %>
732732
# <%= form.text_field :last_name %>
733733
# <%= form.text_area :biography %>
734-
# <%= form.check_box :admin %>
734+
# <%= form.checkbox :admin %>
735735
# <%= form.submit %>
736736
# <% end %>
737737
#
@@ -804,7 +804,7 @@ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block
804804
# Last name : <%= person_form.text_field :last_name %>
805805
#
806806
# <%= fields_for :permission, @person.permission do |permission_fields| %>
807-
# Admin? : <%= permission_fields.check_box :admin %>
807+
# Admin? : <%= permission_fields.checkbox :admin %>
808808
# <% end %>
809809
#
810810
# <%= person_form.submit %>
@@ -821,7 +821,7 @@ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block
821821
# object to +fields_for+ -
822822
#
823823
# <%= fields_for :permission do |permission_fields| %>
824-
# Admin?: <%= permission_fields.check_box :admin %>
824+
# Admin?: <%= permission_fields.checkbox :admin %>
825825
# <% end %>
826826
#
827827
# ...in which case, if <tt>:permission</tt> also happens to be the name of an
@@ -833,7 +833,7 @@ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block
833833
# name has been omitted) -
834834
#
835835
# <%= fields_for @person.permission do |permission_fields| %>
836-
# Admin?: <%= permission_fields.check_box :admin %>
836+
# Admin?: <%= permission_fields.checkbox :admin %>
837837
# <% end %>
838838
#
839839
# and +fields_for+ will derive the required name of the field from the
@@ -914,7 +914,7 @@ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block
914914
# ...
915915
# <%= person_form.fields_for :address do |address_fields| %>
916916
# ...
917-
# Delete: <%= address_fields.check_box :_destroy %>
917+
# Delete: <%= address_fields.checkbox :_destroy %>
918918
# <% end %>
919919
# ...
920920
# <% end %>
@@ -1002,7 +1002,7 @@ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block
10021002
# <%= form_with model: @person do |person_form| %>
10031003
# ...
10041004
# <%= person_form.fields_for :projects do |project_fields| %>
1005-
# Delete: <%= project_fields.check_box :_destroy %>
1005+
# Delete: <%= project_fields.checkbox :_destroy %>
10061006
# <% end %>
10071007
# ...
10081008
# <% end %>
@@ -1070,7 +1070,7 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
10701070
# <%= fields.text_field :body %>
10711071
#
10721072
# <%= text_area :commenter, :biography %>
1073-
# <%= check_box_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
1073+
# <%= checkbox_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
10741074
# <% end %>
10751075
#
10761076
# Same goes for the methods in FormOptionsHelper and DateHelper designed
@@ -1316,35 +1316,36 @@ def text_area(object_name, method, options = {})
13161316
# within an array-like parameter, as in
13171317
#
13181318
# <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
1319-
# <%= form.check_box :paid %>
1319+
# <%= form.checkbox :paid %>
13201320
# ...
13211321
# <% end %>
13221322
#
13231323
# because parameter name repetition is precisely what \Rails seeks to distinguish
13241324
# the elements of the array. For each item with a checked check box you
13251325
# get an extra ghost item with only that attribute, assigned to "0".
13261326
#
1327-
# In that case it is preferable to either use +check_box_tag+ or to use
1327+
# In that case it is preferable to either use +checkbox_tag+ or to use
13281328
# hashes instead of arrays.
13291329
#
13301330
# ==== Examples
13311331
#
13321332
# # Let's say that @article.validated? is 1:
1333-
# check_box("article", "validated")
1333+
# checkbox("article", "validated")
13341334
# # => <input name="article[validated]" type="hidden" value="0" />
13351335
# # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
13361336
#
13371337
# # Let's say that @puppy.gooddog is "no":
1338-
# check_box("puppy", "gooddog", {}, "yes", "no")
1338+
# checkbox("puppy", "gooddog", {}, "yes", "no")
13391339
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
13401340
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
13411341
#
1342-
# check_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
1342+
# checkbox("eula", "accepted", { class: 'eula_check' }, "yes", "no")
13431343
# # => <input name="eula[accepted]" type="hidden" value="no" />
13441344
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
1345-
def check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
1345+
def checkbox(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
13461346
Tags::CheckBox.new(object_name, method, self, checked_value, unchecked_value, options).render
13471347
end
1348+
alias_method :check_box, :checkbox
13481349

13491350
# Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
13501351
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
@@ -1634,12 +1635,12 @@ def default_form_builder_class
16341635
#
16351636
# <%= form_with model: @person do |person_form| %>
16361637
# Name: <%= person_form.text_field :name %>
1637-
# Admin: <%= person_form.check_box :admin %>
1638+
# Admin: <%= person_form.checkbox :admin %>
16381639
# <% end %>
16391640
#
16401641
# In the above block, a +FormBuilder+ object is yielded as the
16411642
# +person_form+ variable. This allows you to generate the +text_field+
1642-
# and +check_box+ fields by specifying their eponymous methods, which
1643+
# and +checkbox+ fields by specifying their eponymous methods, which
16431644
# modify the underlying template and associates the <tt>@person</tt> model object
16441645
# with the form.
16451646
#
@@ -1681,7 +1682,7 @@ class FormBuilder
16811682
# The methods which wrap a form helper call.
16821683
class_attribute :field_helpers, default: [
16831684
:fields_for, :fields, :label, :text_field, :password_field,
1684-
:hidden_field, :file_field, :text_area, :check_box,
1685+
:hidden_field, :file_field, :text_area, :checkbox,
16851686
:radio_button, :color_field, :search_field,
16861687
:telephone_field, :phone_field, :date_field,
16871688
:time_field, :datetime_field, :datetime_local_field,
@@ -2019,7 +2020,7 @@ def field_name(method, *methods, multiple: false, index: @options[:index])
20192020
# Please refer to the documentation of the base helper for details.
20202021

20212022
ActiveSupport::CodeGenerator.batch(self, __FILE__, __LINE__) do |code_generator|
2022-
(field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
2023+
(field_helpers - [:label, :checkbox, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
20232024
code_generator.define_cached_method(selector, namespace: :form_builder) do |batch|
20242025
batch.push <<-RUBY_EVAL
20252026
def #{selector}(method, options = {}) # def text_field(method, options = {})
@@ -2055,7 +2056,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
20552056
# Last name : <%= person_form.text_field :last_name %>
20562057
#
20572058
# <%= fields_for :permission, @person.permission do |permission_fields| %>
2058-
# Admin? : <%= permission_fields.check_box :admin %>
2059+
# Admin? : <%= permission_fields.checkbox :admin %>
20592060
# <% end %>
20602061
#
20612062
# <%= person_form.submit %>
@@ -2072,7 +2073,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
20722073
# object to +fields_for+ -
20732074
#
20742075
# <%= fields_for :permission do |permission_fields| %>
2075-
# Admin?: <%= permission_fields.check_box :admin %>
2076+
# Admin?: <%= permission_fields.checkbox :admin %>
20762077
# <% end %>
20772078
#
20782079
# ...in which case, if <tt>:permission</tt> also happens to be the name of an
@@ -2084,7 +2085,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
20842085
# name has been omitted) -
20852086
#
20862087
# <%= fields_for @person.permission do |permission_fields| %>
2087-
# Admin?: <%= permission_fields.check_box :admin %>
2088+
# Admin?: <%= permission_fields.checkbox :admin %>
20882089
# <% end %>
20892090
#
20902091
# and +fields_for+ will derive the required name of the field from the
@@ -2102,7 +2103,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
21022103
# <%= form_with model: @person do |person_form| %>
21032104
# ...
21042105
# <%= fields_for :permission, @person.permission, {} do |permission_fields| %>
2105-
# Admin?: <%= check_box_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
2106+
# Admin?: <%= checkbox_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
21062107
# <% end %>
21072108
# ...
21082109
# <% end %>
@@ -2177,7 +2178,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
21772178
# ...
21782179
# <%= person_form.fields_for :address do |address_fields| %>
21792180
# ...
2180-
# Delete: <%= address_fields.check_box :_destroy %>
2181+
# Delete: <%= address_fields.checkbox :_destroy %>
21812182
# <% end %>
21822183
# ...
21832184
# <% end %>
@@ -2265,7 +2266,7 @@ def #{selector}(method, options = {}) # def text_field(method, options = {})
22652266
# <%= form_with model: @person do |person_form| %>
22662267
# ...
22672268
# <%= person_form.fields_for :projects do |project_fields| %>
2268-
# Delete: <%= project_fields.check_box :_destroy %>
2269+
# Delete: <%= project_fields.checkbox :_destroy %>
22692270
# <% end %>
22702271
# ...
22712272
# <% end %>
@@ -2444,36 +2445,37 @@ def label(method, text = nil, options = {}, &block)
24442445
# within an array-like parameter, as in
24452446
#
24462447
# <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
2447-
# <%= form.check_box :paid %>
2448+
# <%= form.checkbox :paid %>
24482449
# ...
24492450
# <% end %>
24502451
#
24512452
# because parameter name repetition is precisely what \Rails seeks to distinguish
24522453
# the elements of the array. For each item with a checked check box you
24532454
# get an extra ghost item with only that attribute, assigned to "0".
24542455
#
2455-
# In that case it is preferable to either use +check_box_tag+ or to use
2456+
# In that case it is preferable to either use +checkbox_tag+ or to use
24562457
# hashes instead of arrays.
24572458
#
24582459
# ==== Examples
24592460
#
24602461
# # Let's say that @article.validated? is 1:
2461-
# check_box("validated")
2462+
# checkbox("validated")
24622463
# # => <input name="article[validated]" type="hidden" value="0" />
24632464
# # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
24642465
#
24652466
# # Let's say that @puppy.gooddog is "no":
2466-
# check_box("gooddog", {}, "yes", "no")
2467+
# checkbox("gooddog", {}, "yes", "no")
24672468
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
24682469
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
24692470
#
24702471
# # Let's say that @eula.accepted is "no":
2471-
# check_box("accepted", { class: 'eula_check' }, "yes", "no")
2472+
# checkbox("accepted", { class: 'eula_check' }, "yes", "no")
24722473
# # => <input name="eula[accepted]" type="hidden" value="no" />
24732474
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
2474-
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
2475-
@template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
2475+
def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0")
2476+
@template.checkbox(@object_name, method, objectify_options(options), checked_value, unchecked_value)
24762477
end
2478+
alias_method :check_box, :checkbox
24772479

24782480
# Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
24792481
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the

actionview/lib/action_view/helpers/form_options_helper.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def collection_radio_buttons(object, method, collection, value_method, text_meth
723723
# end
724724
#
725725
# Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
726-
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial)
726+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial)
727727
#
728728
# If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return:
729729
# <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
@@ -736,8 +736,8 @@ def collection_radio_buttons(object, method, collection, value_method, text_meth
736736
#
737737
# It is also possible to customize the way the elements will be shown by
738738
# giving a block to the method:
739-
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
740-
# b.label { b.check_box }
739+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
740+
# b.label { b.checkbox }
741741
# end
742742
#
743743
# The argument passed to the block is a special kind of builder for this
@@ -746,17 +746,17 @@ def collection_radio_buttons(object, method, collection, value_method, text_meth
746746
# Using it, you can change the label and check box display order or even
747747
# use the label as wrapper, as in the example above.
748748
#
749-
# The builder methods <tt>label</tt> and <tt>check_box</tt> also accept
749+
# The builder methods <tt>label</tt> and <tt>checkbox</tt> also accept
750750
# extra HTML options:
751-
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
752-
# b.label(class: "check_box") { b.check_box(class: "check_box") }
751+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
752+
# b.label(class: "checkbox") { b.checkbox(class: "checkbox") }
753753
# end
754754
#
755755
# There are also three special methods available: <tt>object</tt>, <tt>text</tt> and
756756
# <tt>value</tt>, which are the current item being rendered, its text and value methods,
757757
# respectively. You can use them like this:
758-
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
759-
# b.label(:"data-value" => b.value) { b.check_box + b.text }
758+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
759+
# b.label(:"data-value" => b.value) { b.checkbox + b.text }
760760
# end
761761
#
762762
# ==== Gotcha
@@ -779,7 +779,7 @@ def collection_radio_buttons(object, method, collection, value_method, text_meth
779779
#
780780
# In the rare case you don't want this hidden field, you can pass the
781781
# <tt>include_hidden: false</tt> option to the helper method.
782-
def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
782+
def collection_checkboxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
783783
Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
784784
end
785785

@@ -897,16 +897,16 @@ def weekday_select(method, options = {}, html_options = {})
897897
@template.weekday_select(@object_name, method, objectify_options(options), @default_html_options.merge(html_options))
898898
end
899899

900-
# Wraps ActionView::Helpers::FormOptionsHelper#collection_check_boxes for form builders:
900+
# Wraps ActionView::Helpers::FormOptionsHelper#collection_checkboxes for form builders:
901901
#
902902
# <%= form_for @post do |f| %>
903-
# <%= f.collection_check_boxes :author_ids, Author.all, :id, :name_with_initial %>
903+
# <%= f.collection_checkboxes :author_ids, Author.all, :id, :name_with_initial %>
904904
# <%= f.submit %>
905905
# <% end %>
906906
#
907907
# Please refer to the documentation of the base helper for details.
908-
def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
909-
@template.collection_check_boxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
908+
def collection_checkboxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
909+
@template.collection_checkboxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
910910
end
911911

912912
# Wraps ActionView::Helpers::FormOptionsHelper#collection_radio_buttons for form builders:

0 commit comments

Comments
 (0)