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