actionview 7.2.3 → 8.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -186
  3. data/README.rdoc +1 -1
  4. data/lib/action_view/base.rb +9 -6
  5. data/lib/action_view/dependency_tracker/erb_tracker.rb +35 -27
  6. data/lib/action_view/dependency_tracker/ruby_tracker.rb +2 -19
  7. data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
  8. data/lib/action_view/dependency_tracker.rb +1 -0
  9. data/lib/action_view/digestor.rb +2 -6
  10. data/lib/action_view/gem_version.rb +4 -4
  11. data/lib/action_view/helpers/asset_tag_helper.rb +4 -4
  12. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  13. data/lib/action_view/helpers/cache_helper.rb +10 -2
  14. data/lib/action_view/helpers/date_helper.rb +1 -8
  15. data/lib/action_view/helpers/form_helper.rb +90 -91
  16. data/lib/action_view/helpers/form_options_helper.rb +19 -20
  17. data/lib/action_view/helpers/form_tag_helper.rb +18 -16
  18. data/lib/action_view/helpers/output_safety_helper.rb +2 -1
  19. data/lib/action_view/helpers/rendering_helper.rb +160 -50
  20. data/lib/action_view/helpers/tag_helper.rb +41 -38
  21. data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
  22. data/lib/action_view/helpers/tags/collection_helpers.rb +1 -2
  23. data/lib/action_view/helpers/text_helper.rb +4 -11
  24. data/lib/action_view/helpers/url_helper.rb +2 -4
  25. data/lib/action_view/layouts.rb +7 -7
  26. data/lib/action_view/render_parser/prism_render_parser.rb +13 -1
  27. data/lib/action_view/render_parser/ripper_render_parser.rb +10 -1
  28. data/lib/action_view/renderer/partial_renderer.rb +2 -2
  29. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -1
  30. data/lib/action_view/renderer/template_renderer.rb +3 -3
  31. data/lib/action_view/rendering.rb +2 -3
  32. data/lib/action_view/template/error.rb +0 -11
  33. data/lib/action_view/template/handlers/erb.rb +37 -45
  34. data/lib/action_view/template/resolver.rb +0 -1
  35. data/lib/action_view/template.rb +3 -14
  36. data/lib/action_view/test_case.rb +1 -0
  37. data/lib/action_view.rb +0 -1
  38. metadata +17 -27
@@ -30,8 +30,8 @@ module ActionView
30
30
  # when the form is initially displayed, input fields corresponding to attributes
31
31
  # of the resource should show the current values of those attributes.
32
32
  #
33
- # In \Rails, this is usually achieved by creating the form using #form_for and
34
- # a number of related helper methods. #form_for generates an appropriate <tt>form</tt>
33
+ # In \Rails, this is usually achieved by creating the form using +form_for+ and
34
+ # a number of related helper methods. +form_for+ generates an appropriate <tt>form</tt>
35
35
  # tag and yields a form builder object that knows the model the form is about.
36
36
  # Input fields are created by calling methods defined on the form builder, which
37
37
  # means they are able to generate the appropriate names and default values
@@ -41,7 +41,7 @@ module ActionView
41
41
  #
42
42
  # For example, to create a new person you typically set up a new instance of
43
43
  # +Person+ in the <tt>PeopleController#new</tt> action, <tt>@person</tt>, and
44
- # in the view template pass that object to #form_for:
44
+ # in the view template pass that object to +form_for+:
45
45
  #
46
46
  # <%= form_for @person do |f| %>
47
47
  # <%= f.label :first_name %>:
@@ -132,8 +132,8 @@ module ActionView
132
132
  # <%= form_for :person do |f| %>
133
133
  # First name: <%= f.text_field :first_name %><br />
134
134
  # Last name : <%= f.text_field :last_name %><br />
135
- # Biography : <%= f.text_area :biography %><br />
136
- # Admin? : <%= f.check_box :admin %><br />
135
+ # Biography : <%= f.textarea :biography %><br />
136
+ # Admin? : <%= f.checkbox :admin %><br />
137
137
  # <%= f.submit %>
138
138
  # <% end %>
139
139
  #
@@ -199,8 +199,8 @@ module ActionView
199
199
  # <%= form_for :person do |f| %>
200
200
  # First name: <%= f.text_field :first_name %>
201
201
  # Last name : <%= f.text_field :last_name %>
202
- # Biography : <%= text_area :person, :biography %>
203
- # Admin? : <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
202
+ # Biography : <%= textarea :person, :biography %>
203
+ # Admin? : <%= checkbox_tag "person[admin]", "1", @person.company.admin? %>
204
204
  # <%= f.submit %>
205
205
  # <% end %>
206
206
  #
@@ -208,7 +208,7 @@ module ActionView
208
208
  # are designed to work with an object as base, like
209
209
  # FormOptionsHelper#collection_select and DateHelper#datetime_select.
210
210
  #
211
- # === +form_for+ with a model object
211
+ # === #form_for with a model object
212
212
  #
213
213
  # In the examples above, the object to be created or edited was
214
214
  # represented by a symbol passed to +form_for+, and we noted that
@@ -363,7 +363,7 @@ module ActionView
363
363
  #
364
364
  # === Removing hidden model id's
365
365
  #
366
- # The +form_for+ method automatically includes the model id as a hidden field in the form.
366
+ # The form_for method automatically includes the model id as a hidden field in the form.
367
367
  # This is used to maintain the correlation between the form data and its associated model.
368
368
  # Some ORM systems do not use IDs on nested models so in this case you want to be able
369
369
  # to disable the hidden id.
@@ -389,8 +389,8 @@ module ActionView
389
389
  # <%= form_for @person, url: { action: "create" }, builder: LabellingFormBuilder do |f| %>
390
390
  # <%= f.text_field :first_name %>
391
391
  # <%= f.text_field :last_name %>
392
- # <%= f.text_area :biography %>
393
- # <%= f.check_box :admin %>
392
+ # <%= f.textarea :biography %>
393
+ # <%= f.checkbox :admin %>
394
394
  # <%= f.submit %>
395
395
  # <% end %>
396
396
  #
@@ -668,8 +668,8 @@ module ActionView
668
668
  # <%= form.text_field :first_name %>
669
669
  # <%= form.text_field :last_name %>
670
670
  #
671
- # <%= text_area :person, :biography %>
672
- # <%= check_box_tag "person[admin]", "1", @person.company.admin? %>
671
+ # <%= textarea :person, :biography %>
672
+ # <%= checkbox_tag "person[admin]", "1", @person.company.admin? %>
673
673
  #
674
674
  # <%= form.submit %>
675
675
  # <% end %>
@@ -730,8 +730,8 @@ module ActionView
730
730
  # <%= form_with model: @person, url: { action: "create" }, builder: LabellingFormBuilder do |form| %>
731
731
  # <%= form.text_field :first_name %>
732
732
  # <%= form.text_field :last_name %>
733
- # <%= form.text_area :biography %>
734
- # <%= form.check_box :admin %>
733
+ # <%= form.textarea :biography %>
734
+ # <%= form.checkbox :admin %>
735
735
  # <%= form.submit %>
736
736
  # <% end %>
737
737
  #
@@ -783,12 +783,12 @@ module ActionView
783
783
  end
784
784
  end
785
785
 
786
- # Creates a scope around a specific model object like #form_with, but
786
+ # Creates a scope around a specific model object like form_with, but
787
787
  # doesn't create the form tags themselves. This makes fields_for suitable
788
788
  # for specifying additional model objects in the same form.
789
789
  #
790
- # Although the usage and purpose of +fields_for+ is similar to #form_with's,
791
- # its method signature is slightly different. Like #form_with, it yields
790
+ # Although the usage and purpose of +fields_for+ is similar to +form_with+'s,
791
+ # its method signature is slightly different. Like +form_with+, it yields
792
792
  # a FormBuilder object associated with a particular model object to a block,
793
793
  # and within the block allows methods to be called on the builder to
794
794
  # generate fields associated with the model object. Fields may reflect
@@ -804,7 +804,7 @@ module ActionView
804
804
  # Last name : <%= person_form.text_field :last_name %>
805
805
  #
806
806
  # <%= fields_for :permission, @person.permission do |permission_fields| %>
807
- # Admin? : <%= permission_fields.check_box :admin %>
807
+ # Admin? : <%= permission_fields.checkbox :admin %>
808
808
  # <% end %>
809
809
  #
810
810
  # <%= person_form.submit %>
@@ -821,7 +821,7 @@ module ActionView
821
821
  # object to +fields_for+ -
822
822
  #
823
823
  # <%= fields_for :permission do |permission_fields| %>
824
- # Admin?: <%= permission_fields.check_box :admin %>
824
+ # Admin?: <%= permission_fields.checkbox :admin %>
825
825
  # <% end %>
826
826
  #
827
827
  # ...in which case, if <tt>:permission</tt> also happens to be the name of an
@@ -833,7 +833,7 @@ module ActionView
833
833
  # name has been omitted) -
834
834
  #
835
835
  # <%= fields_for @person.permission do |permission_fields| %>
836
- # Admin?: <%= permission_fields.check_box :admin %>
836
+ # Admin?: <%= permission_fields.checkbox :admin %>
837
837
  # <% end %>
838
838
  #
839
839
  # and +fields_for+ will derive the required name of the field from the
@@ -847,7 +847,7 @@ module ActionView
847
847
  # === Nested Attributes Examples
848
848
  #
849
849
  # When the object belonging to the current scope has a nested attribute
850
- # writer for a certain attribute, +fields_for+ will yield a new scope
850
+ # writer for a certain attribute, fields_for will yield a new scope
851
851
  # for that attribute. This allows you to create forms that set or change
852
852
  # the attributes of a parent object and its associations in one go.
853
853
  #
@@ -914,7 +914,7 @@ module ActionView
914
914
  # ...
915
915
  # <%= person_form.fields_for :address do |address_fields| %>
916
916
  # ...
917
- # Delete: <%= address_fields.check_box :_destroy %>
917
+ # Delete: <%= address_fields.checkbox :_destroy %>
918
918
  # <% end %>
919
919
  # ...
920
920
  # <% end %>
@@ -936,7 +936,7 @@ module ActionView
936
936
  # end
937
937
  #
938
938
  # Note that the <tt>projects_attributes=</tt> writer method is in fact
939
- # required for +fields_for+ to correctly identify <tt>:projects</tt> as a
939
+ # required for fields_for to correctly identify <tt>:projects</tt> as a
940
940
  # collection, and the correct indices to be set in the form markup.
941
941
  #
942
942
  # When projects is already an association on Person you can use
@@ -948,7 +948,7 @@ module ActionView
948
948
  # end
949
949
  #
950
950
  # This model can now be used with a nested fields_for. The block given to
951
- # the nested +fields_for+ call will be repeated for each instance in the
951
+ # the nested fields_for call will be repeated for each instance in the
952
952
  # collection:
953
953
  #
954
954
  # <%= form_with model: @person do |person_form| %>
@@ -1002,7 +1002,7 @@ module ActionView
1002
1002
  # <%= form_with model: @person do |person_form| %>
1003
1003
  # ...
1004
1004
  # <%= person_form.fields_for :projects do |project_fields| %>
1005
- # Delete: <%= project_fields.check_box :_destroy %>
1005
+ # Delete: <%= project_fields.checkbox :_destroy %>
1006
1006
  # <% end %>
1007
1007
  # ...
1008
1008
  # <% end %>
@@ -1020,10 +1020,10 @@ module ActionView
1020
1020
  # ...
1021
1021
  # <% end %>
1022
1022
  #
1023
- # Note that +fields_for+ will automatically generate a hidden field
1023
+ # Note that fields_for will automatically generate a hidden field
1024
1024
  # to store the ID of the record if it responds to <tt>persisted?</tt>.
1025
1025
  # There are circumstances where this hidden field is not needed and you
1026
- # can pass <tt>include_id: false</tt> to prevent +fields_for+ from
1026
+ # can pass <tt>include_id: false</tt> to prevent fields_for from
1027
1027
  # rendering it automatically.
1028
1028
  def fields_for(record_name, record_object = nil, options = {}, &block)
1029
1029
  options = { model: record_object, allow_method_names_outside_object: false, skip_default_ids: false }.merge!(options)
@@ -1032,7 +1032,7 @@ module ActionView
1032
1032
  end
1033
1033
 
1034
1034
  # Scopes input fields with either an explicit scope or model.
1035
- # Like #form_with does with <tt>:scope</tt> or <tt>:model</tt>,
1035
+ # Like +form_with+ does with <tt>:scope</tt> or <tt>:model</tt>,
1036
1036
  # except it doesn't output the form tags.
1037
1037
  #
1038
1038
  # # Using a scope prefixes the input field names:
@@ -1047,7 +1047,7 @@ module ActionView
1047
1047
  # <% end %>
1048
1048
  # # => <input type="text" name="comment[body]" value="full bodied">
1049
1049
  #
1050
- # # Using `fields` with `form_with`:
1050
+ # # Using +fields+ with +form_with+:
1051
1051
  # <%= form_with model: @article do |form| %>
1052
1052
  # <%= form.text_field :title %>
1053
1053
  #
@@ -1056,21 +1056,21 @@ module ActionView
1056
1056
  # <% end %>
1057
1057
  # <% end %>
1058
1058
  #
1059
- # Much like #form_with a FormBuilder instance associated with the scope
1059
+ # Much like +form_with+ a FormBuilder instance associated with the scope
1060
1060
  # or model is yielded, so any generated field names are prefixed with
1061
1061
  # either the passed scope or the scope inferred from the <tt>:model</tt>.
1062
1062
  #
1063
1063
  # === Mixing with other form helpers
1064
1064
  #
1065
- # While #form_with uses a FormBuilder object it's possible to mix and
1065
+ # While +form_with+ uses a FormBuilder object it's possible to mix and
1066
1066
  # match the stand-alone FormHelper methods and methods
1067
1067
  # from FormTagHelper:
1068
1068
  #
1069
1069
  # <%= fields model: @comment do |fields| %>
1070
1070
  # <%= fields.text_field :body %>
1071
1071
  #
1072
- # <%= text_area :commenter, :biography %>
1073
- # <%= check_box_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
1072
+ # <%= textarea :commenter, :biography %>
1073
+ # <%= checkbox_tag "comment[all_caps]", "1", @comment.commenter.hulk_mode? %>
1074
1074
  # <% end %>
1075
1075
  #
1076
1076
  # Same goes for the methods in FormOptionsHelper and DateHelper designed
@@ -1220,7 +1220,7 @@ module ActionView
1220
1220
  # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
1221
1221
  # shown.
1222
1222
  #
1223
- # Using this method inside a #form_with block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
1223
+ # Using this method inside a +form_with+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
1224
1224
  #
1225
1225
  # ==== Options
1226
1226
  # * Creates standard HTML attributes for the tag.
@@ -1255,28 +1255,29 @@ module ActionView
1255
1255
  # hash with +options+.
1256
1256
  #
1257
1257
  # ==== Examples
1258
- # text_area(:article, :body, cols: 20, rows: 40)
1258
+ # textarea(:article, :body, cols: 20, rows: 40)
1259
1259
  # # => <textarea cols="20" rows="40" id="article_body" name="article[body]">
1260
1260
  # # #{@article.body}
1261
1261
  # # </textarea>
1262
1262
  #
1263
- # text_area(:comment, :text, size: "20x30")
1263
+ # textarea(:comment, :text, size: "20x30")
1264
1264
  # # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
1265
1265
  # # #{@comment.text}
1266
1266
  # # </textarea>
1267
1267
  #
1268
- # text_area(:application, :notes, cols: 40, rows: 15, class: 'app_input')
1268
+ # textarea(:application, :notes, cols: 40, rows: 15, class: 'app_input')
1269
1269
  # # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
1270
1270
  # # #{@application.notes}
1271
1271
  # # </textarea>
1272
1272
  #
1273
- # text_area(:entry, :body, size: "20x20", disabled: 'disabled')
1273
+ # textarea(:entry, :body, size: "20x20", disabled: 'disabled')
1274
1274
  # # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
1275
1275
  # # #{@entry.body}
1276
1276
  # # </textarea>
1277
- def text_area(object_name, method, options = {})
1277
+ def textarea(object_name, method, options = {})
1278
1278
  Tags::TextArea.new(object_name, method, self, options).render
1279
1279
  end
1280
+ alias_method :text_area, :textarea
1280
1281
 
1281
1282
  # Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object
1282
1283
  # assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object.
@@ -1316,7 +1317,7 @@ module ActionView
1316
1317
  # within an array-like parameter, as in
1317
1318
  #
1318
1319
  # <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
1319
- # <%= form.check_box :paid %>
1320
+ # <%= form.checkbox :paid %>
1320
1321
  # ...
1321
1322
  # <% end %>
1322
1323
  #
@@ -1324,27 +1325,28 @@ module ActionView
1324
1325
  # the elements of the array. For each item with a checked check box you
1325
1326
  # get an extra ghost item with only that attribute, assigned to "0".
1326
1327
  #
1327
- # In that case it is preferable to either use FormTagHelper#check_box_tag or to use
1328
+ # In that case it is preferable to either use +checkbox_tag+ or to use
1328
1329
  # hashes instead of arrays.
1329
1330
  #
1330
1331
  # ==== Examples
1331
1332
  #
1332
1333
  # # Let's say that @article.validated? is 1:
1333
- # check_box("article", "validated")
1334
+ # checkbox("article", "validated")
1334
1335
  # # => <input name="article[validated]" type="hidden" value="0" />
1335
1336
  # # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
1336
1337
  #
1337
1338
  # # Let's say that @puppy.gooddog is "no":
1338
- # check_box("puppy", "gooddog", {}, "yes", "no")
1339
+ # checkbox("puppy", "gooddog", {}, "yes", "no")
1339
1340
  # # => <input name="puppy[gooddog]" type="hidden" value="no" />
1340
1341
  # # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
1341
1342
  #
1342
- # check_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
1343
+ # checkbox("eula", "accepted", { class: 'eula_check' }, "yes", "no")
1343
1344
  # # => <input name="eula[accepted]" type="hidden" value="no" />
1344
1345
  # # <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")
1346
+ def checkbox(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
1346
1347
  Tags::CheckBox.new(object_name, method, self, checked_value, unchecked_value, options).render
1347
1348
  end
1349
+ alias_method :check_box, :checkbox
1348
1350
 
1349
1351
  # Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
1350
1352
  # assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
@@ -1629,17 +1631,17 @@ module ActionView
1629
1631
  #
1630
1632
  # A +FormBuilder+ object is associated with a particular model object and
1631
1633
  # allows you to generate fields associated with the model object. The
1632
- # +FormBuilder+ object is yielded when using #form_with or #fields_for.
1634
+ # +FormBuilder+ object is yielded when using +form_with+ or +fields_for+.
1633
1635
  # For example:
1634
1636
  #
1635
1637
  # <%= form_with model: @person do |person_form| %>
1636
1638
  # Name: <%= person_form.text_field :name %>
1637
- # Admin: <%= person_form.check_box :admin %>
1639
+ # Admin: <%= person_form.checkbox :admin %>
1638
1640
  # <% end %>
1639
1641
  #
1640
1642
  # In the above block, a +FormBuilder+ object is yielded as the
1641
1643
  # +person_form+ variable. This allows you to generate the +text_field+
1642
- # and +check_box+ fields by specifying their eponymous methods, which
1644
+ # and +checkbox+ fields by specifying their eponymous methods, which
1643
1645
  # modify the underlying template and associates the <tt>@person</tt> model object
1644
1646
  # with the form.
1645
1647
  #
@@ -1681,7 +1683,7 @@ module ActionView
1681
1683
  # The methods which wrap a form helper call.
1682
1684
  class_attribute :field_helpers, default: [
1683
1685
  :fields_for, :fields, :label, :text_field, :password_field,
1684
- :hidden_field, :file_field, :text_area, :check_box,
1686
+ :hidden_field, :file_field, :textarea, :checkbox,
1685
1687
  :radio_button, :color_field, :search_field,
1686
1688
  :telephone_field, :phone_field, :date_field,
1687
1689
  :time_field, :datetime_field, :datetime_local_field,
@@ -1767,7 +1769,7 @@ module ActionView
1767
1769
  # <% end %>
1768
1770
  #
1769
1771
  # In the example above, the <tt><input type="text"></tt> element built by
1770
- # the call to #text_field declares an
1772
+ # the call to <tt>FormBuilder#text_field</tt> declares an
1771
1773
  # <tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
1772
1774
  # element, sharing a common <tt>id</tt> root (<tt>article_title</tt>, in this
1773
1775
  # case).
@@ -1824,14 +1826,14 @@ module ActionView
1824
1826
  # Please refer to the documentation of the base helper for details.
1825
1827
 
1826
1828
  ##
1827
- # :method: text_area
1829
+ # :method: textarea
1828
1830
  #
1829
- # :call-seq: text_area(method, options = {})
1831
+ # :call-seq: textarea(method, options = {})
1830
1832
  #
1831
- # Wraps ActionView::Helpers::FormHelper#text_area for form builders:
1833
+ # Wraps ActionView::Helpers::FormHelper#textarea for form builders:
1832
1834
  #
1833
1835
  # <%= form_with model: @user do |f| %>
1834
- # <%= f.text_area :detail %>
1836
+ # <%= f.textarea :detail %>
1835
1837
  # <% end %>
1836
1838
  #
1837
1839
  # Please refer to the documentation of the base helper for details.
@@ -2019,27 +2021,23 @@ module ActionView
2019
2021
  # Please refer to the documentation of the base helper for details.
2020
2022
 
2021
2023
  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
- code_generator.define_cached_method(selector, namespace: :form_builder) do |batch|
2024
- batch.push <<-RUBY_EVAL
2025
- def #{selector}(method, options = {}) # def text_field(method, options = {})
2026
- @template.public_send( # @template.public_send(
2027
- #{selector.inspect}, # :text_field,
2028
- @object_name, # @object_name,
2029
- method, # method,
2030
- objectify_options(options)) # objectify_options(options))
2031
- end # end
2032
- RUBY_EVAL
2024
+ (field_helpers - [:label, :checkbox, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
2025
+ code_generator.class_eval do |batch|
2026
+ batch <<
2027
+ "def #{selector}(method, options = {})" <<
2028
+ " @template.#{selector}(@object_name, method, objectify_options(options))" <<
2029
+ "end"
2030
+ end
2033
2031
  end
2034
- end
2035
2032
  end
2033
+ alias_method :text_area, :textarea
2036
2034
 
2037
- # Creates a scope around a specific model object like #form_with, but
2035
+ # Creates a scope around a specific model object like form_with, but
2038
2036
  # doesn't create the form tags themselves. This makes fields_for suitable
2039
2037
  # for specifying additional model objects in the same form.
2040
2038
  #
2041
- # Although the usage and purpose of +fields_for+ is similar to #form_with's,
2042
- # its method signature is slightly different. Like #form_with, it yields
2039
+ # Although the usage and purpose of +fields_for+ is similar to +form_with+'s,
2040
+ # its method signature is slightly different. Like +form_with+, it yields
2043
2041
  # a FormBuilder object associated with a particular model object to a block,
2044
2042
  # and within the block allows methods to be called on the builder to
2045
2043
  # generate fields associated with the model object. Fields may reflect
@@ -2055,7 +2053,7 @@ module ActionView
2055
2053
  # Last name : <%= person_form.text_field :last_name %>
2056
2054
  #
2057
2055
  # <%= fields_for :permission, @person.permission do |permission_fields| %>
2058
- # Admin? : <%= permission_fields.check_box :admin %>
2056
+ # Admin? : <%= permission_fields.checkbox :admin %>
2059
2057
  # <% end %>
2060
2058
  #
2061
2059
  # <%= person_form.submit %>
@@ -2072,7 +2070,7 @@ module ActionView
2072
2070
  # object to +fields_for+ -
2073
2071
  #
2074
2072
  # <%= fields_for :permission do |permission_fields| %>
2075
- # Admin?: <%= permission_fields.check_box :admin %>
2073
+ # Admin?: <%= permission_fields.checkbox :admin %>
2076
2074
  # <% end %>
2077
2075
  #
2078
2076
  # ...in which case, if <tt>:permission</tt> also happens to be the name of an
@@ -2084,7 +2082,7 @@ module ActionView
2084
2082
  # name has been omitted) -
2085
2083
  #
2086
2084
  # <%= fields_for @person.permission do |permission_fields| %>
2087
- # Admin?: <%= permission_fields.check_box :admin %>
2085
+ # Admin?: <%= permission_fields.checkbox :admin %>
2088
2086
  # <% end %>
2089
2087
  #
2090
2088
  # and +fields_for+ will derive the required name of the field from the
@@ -2102,7 +2100,7 @@ module ActionView
2102
2100
  # <%= form_with model: @person do |person_form| %>
2103
2101
  # ...
2104
2102
  # <%= fields_for :permission, @person.permission, {} do |permission_fields| %>
2105
- # Admin?: <%= check_box_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
2103
+ # Admin?: <%= checkbox_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
2106
2104
  # <% end %>
2107
2105
  # ...
2108
2106
  # <% end %>
@@ -2110,7 +2108,7 @@ module ActionView
2110
2108
  # === Nested Attributes Examples
2111
2109
  #
2112
2110
  # When the object belonging to the current scope has a nested attribute
2113
- # writer for a certain attribute, +fields_for+ will yield a new scope
2111
+ # writer for a certain attribute, fields_for will yield a new scope
2114
2112
  # for that attribute. This allows you to create forms that set or change
2115
2113
  # the attributes of a parent object and its associations in one go.
2116
2114
  #
@@ -2141,7 +2139,7 @@ module ActionView
2141
2139
  # end
2142
2140
  # end
2143
2141
  #
2144
- # This model can now be used with a nested +fields_for+, like so:
2142
+ # This model can now be used with a nested fields_for, like so:
2145
2143
  #
2146
2144
  # <%= form_with model: @person do |person_form| %>
2147
2145
  # ...
@@ -2177,7 +2175,7 @@ module ActionView
2177
2175
  # ...
2178
2176
  # <%= person_form.fields_for :address do |address_fields| %>
2179
2177
  # ...
2180
- # Delete: <%= address_fields.check_box :_destroy %>
2178
+ # Delete: <%= address_fields.checkbox :_destroy %>
2181
2179
  # <% end %>
2182
2180
  # ...
2183
2181
  # <% end %>
@@ -2199,7 +2197,7 @@ module ActionView
2199
2197
  # end
2200
2198
  #
2201
2199
  # Note that the <tt>projects_attributes=</tt> writer method is in fact
2202
- # required for +fields_for+ to correctly identify <tt>:projects</tt> as a
2200
+ # required for fields_for to correctly identify <tt>:projects</tt> as a
2203
2201
  # collection, and the correct indices to be set in the form markup.
2204
2202
  #
2205
2203
  # When projects is already an association on Person you can use
@@ -2210,8 +2208,8 @@ module ActionView
2210
2208
  # accepts_nested_attributes_for :projects
2211
2209
  # end
2212
2210
  #
2213
- # This model can now be used with a nested +fields_for+. The block given to
2214
- # the nested +fields_for+ call will be repeated for each instance in the
2211
+ # This model can now be used with a nested fields_for. The block given to
2212
+ # the nested fields_for call will be repeated for each instance in the
2215
2213
  # collection:
2216
2214
  #
2217
2215
  # <%= form_with model: @person do |person_form| %>
@@ -2265,7 +2263,7 @@ module ActionView
2265
2263
  # <%= form_with model: @person do |person_form| %>
2266
2264
  # ...
2267
2265
  # <%= person_form.fields_for :projects do |project_fields| %>
2268
- # Delete: <%= project_fields.check_box :_destroy %>
2266
+ # Delete: <%= project_fields.checkbox :_destroy %>
2269
2267
  # <% end %>
2270
2268
  # ...
2271
2269
  # <% end %>
@@ -2283,10 +2281,10 @@ module ActionView
2283
2281
  # ...
2284
2282
  # <% end %>
2285
2283
  #
2286
- # Note that +fields_for+ will automatically generate a hidden field
2284
+ # Note that fields_for will automatically generate a hidden field
2287
2285
  # to store the ID of the record. There are circumstances where this
2288
2286
  # hidden field is not needed and you can pass <tt>include_id: false</tt>
2289
- # to prevent +fields_for+ from rendering it automatically.
2287
+ # to prevent fields_for from rendering it automatically.
2290
2288
  def fields_for(record_name, record_object = nil, fields_options = nil, &block)
2291
2289
  fields_options, record_object = record_object, nil if fields_options.nil? && record_object.is_a?(Hash) && record_object.extractable_options?
2292
2290
  fields_options ||= {}
@@ -2444,7 +2442,7 @@ module ActionView
2444
2442
  # within an array-like parameter, as in
2445
2443
  #
2446
2444
  # <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
2447
- # <%= form.check_box :paid %>
2445
+ # <%= form.checkbox :paid %>
2448
2446
  # ...
2449
2447
  # <% end %>
2450
2448
  #
@@ -2452,28 +2450,29 @@ module ActionView
2452
2450
  # the elements of the array. For each item with a checked check box you
2453
2451
  # get an extra ghost item with only that attribute, assigned to "0".
2454
2452
  #
2455
- # In that case it is preferable to either use FormTagHelper#check_box_tag or to use
2453
+ # In that case it is preferable to either use +checkbox_tag+ or to use
2456
2454
  # hashes instead of arrays.
2457
2455
  #
2458
2456
  # ==== Examples
2459
2457
  #
2460
2458
  # # Let's say that @article.validated? is 1:
2461
- # check_box("validated")
2459
+ # checkbox("validated")
2462
2460
  # # => <input name="article[validated]" type="hidden" value="0" />
2463
2461
  # # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
2464
2462
  #
2465
2463
  # # Let's say that @puppy.gooddog is "no":
2466
- # check_box("gooddog", {}, "yes", "no")
2464
+ # checkbox("gooddog", {}, "yes", "no")
2467
2465
  # # => <input name="puppy[gooddog]" type="hidden" value="no" />
2468
2466
  # # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
2469
2467
  #
2470
2468
  # # Let's say that @eula.accepted is "no":
2471
- # check_box("accepted", { class: 'eula_check' }, "yes", "no")
2469
+ # checkbox("accepted", { class: 'eula_check' }, "yes", "no")
2472
2470
  # # => <input name="eula[accepted]" type="hidden" value="no" />
2473
2471
  # # <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)
2472
+ def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0")
2473
+ @template.checkbox(@object_name, method, objectify_options(options), checked_value, unchecked_value)
2476
2474
  end
2475
+ alias_method :check_box, :checkbox
2477
2476
 
2478
2477
  # Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
2479
2478
  # assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
@@ -2525,7 +2524,7 @@ module ActionView
2525
2524
  # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
2526
2525
  # shown.
2527
2526
  #
2528
- # Using this method inside a #form_with block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
2527
+ # Using this method inside a +form_with+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
2529
2528
  #
2530
2529
  # ==== Options
2531
2530
  # * Creates standard HTML attributes for the tag.