actionview 4.2.11.1 → 5.2.4.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionview might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +89 -282
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -6
- data/lib/action_view/base.rb +38 -28
- data/lib/action_view/buffers.rb +3 -1
- data/lib/action_view/context.rb +3 -3
- data/lib/action_view/dependency_tracker.rb +54 -20
- data/lib/action_view/digestor.rb +94 -83
- data/lib/action_view/flows.rb +11 -11
- data/lib/action_view/gem_version.rb +5 -3
- data/lib/action_view/helpers/active_model_helper.rb +17 -11
- data/lib/action_view/helpers/asset_tag_helper.rb +244 -62
- data/lib/action_view/helpers/asset_url_helper.rb +170 -67
- data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
- data/lib/action_view/helpers/cache_helper.rb +105 -42
- data/lib/action_view/helpers/capture_helper.rb +16 -13
- data/lib/action_view/helpers/controller_helper.rb +15 -4
- data/lib/action_view/helpers/csp_helper.rb +24 -0
- data/lib/action_view/helpers/csrf_helper.rb +7 -5
- data/lib/action_view/helpers/date_helper.rb +170 -112
- data/lib/action_view/helpers/debug_helper.rb +7 -6
- data/lib/action_view/helpers/form_helper.rb +521 -127
- data/lib/action_view/helpers/form_options_helper.rb +109 -63
- data/lib/action_view/helpers/form_tag_helper.rb +110 -67
- data/lib/action_view/helpers/javascript_helper.rb +27 -12
- data/lib/action_view/helpers/number_helper.rb +77 -58
- data/lib/action_view/helpers/output_safety_helper.rb +36 -4
- data/lib/action_view/helpers/record_tag_helper.rb +14 -99
- data/lib/action_view/helpers/rendering_helper.rb +6 -5
- data/lib/action_view/helpers/sanitize_helper.rb +20 -15
- data/lib/action_view/helpers/tag_helper.rb +198 -73
- data/lib/action_view/helpers/tags/base.rb +134 -97
- data/lib/action_view/helpers/tags/check_box.rb +20 -18
- data/lib/action_view/helpers/tags/checkable.rb +4 -2
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -33
- data/lib/action_view/helpers/tags/collection_helpers.rb +70 -36
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -11
- data/lib/action_view/helpers/tags/collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/color_field.rb +3 -1
- data/lib/action_view/helpers/tags/date_field.rb +2 -0
- data/lib/action_view/helpers/tags/date_select.rb +38 -36
- data/lib/action_view/helpers/tags/datetime_field.rb +4 -2
- data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
- data/lib/action_view/helpers/tags/email_field.rb +2 -0
- data/lib/action_view/helpers/tags/file_field.rb +2 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
- data/lib/action_view/helpers/tags/hidden_field.rb +2 -0
- data/lib/action_view/helpers/tags/label.rb +3 -1
- data/lib/action_view/helpers/tags/month_field.rb +2 -0
- data/lib/action_view/helpers/tags/number_field.rb +2 -0
- data/lib/action_view/helpers/tags/password_field.rb +3 -1
- data/lib/action_view/helpers/tags/placeholderable.rb +3 -1
- data/lib/action_view/helpers/tags/radio_button.rb +7 -5
- data/lib/action_view/helpers/tags/range_field.rb +2 -0
- data/lib/action_view/helpers/tags/search_field.rb +14 -9
- data/lib/action_view/helpers/tags/select.rb +11 -9
- data/lib/action_view/helpers/tags/tel_field.rb +2 -0
- data/lib/action_view/helpers/tags/text_area.rb +4 -2
- data/lib/action_view/helpers/tags/text_field.rb +8 -7
- data/lib/action_view/helpers/tags/time_field.rb +2 -0
- data/lib/action_view/helpers/tags/time_select.rb +2 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
- data/lib/action_view/helpers/tags/translator.rb +17 -13
- data/lib/action_view/helpers/tags/url_field.rb +2 -0
- data/lib/action_view/helpers/tags/week_field.rb +2 -0
- data/lib/action_view/helpers/tags.rb +3 -1
- data/lib/action_view/helpers/text_helper.rb +55 -36
- data/lib/action_view/helpers/translation_helper.rb +62 -31
- data/lib/action_view/helpers/url_helper.rb +159 -104
- data/lib/action_view/helpers.rb +5 -1
- data/lib/action_view/layouts.rb +65 -58
- data/lib/action_view/log_subscriber.rb +60 -8
- data/lib/action_view/lookup_context.rb +80 -65
- data/lib/action_view/model_naming.rb +3 -1
- data/lib/action_view/path_set.rb +30 -19
- data/lib/action_view/railtie.rb +39 -6
- data/lib/action_view/record_identifier.rb +53 -25
- data/lib/action_view/renderer/abstract_renderer.rb +21 -15
- data/lib/action_view/renderer/partial_renderer/collection_caching.rb +57 -0
- data/lib/action_view/renderer/partial_renderer.rb +218 -214
- data/lib/action_view/renderer/renderer.rb +8 -6
- data/lib/action_view/renderer/streaming_template_renderer.rb +50 -48
- data/lib/action_view/renderer/template_renderer.rb +67 -66
- data/lib/action_view/rendering.rb +19 -14
- data/lib/action_view/routing_url_for.rb +27 -17
- data/lib/action_view/tasks/cache_digests.rake +25 -0
- data/lib/action_view/template/error.rb +16 -16
- data/lib/action_view/template/handlers/builder.rb +10 -11
- data/lib/action_view/template/handlers/erb/erubi.rb +83 -0
- data/lib/action_view/template/handlers/erb.rb +9 -80
- data/lib/action_view/template/handlers/html.rb +11 -0
- data/lib/action_view/template/handlers/raw.rb +3 -3
- data/lib/action_view/template/handlers.rb +11 -7
- data/lib/action_view/template/html.rb +5 -5
- data/lib/action_view/template/resolver.rb +140 -115
- data/lib/action_view/template/text.rb +8 -9
- data/lib/action_view/template/types.rb +18 -18
- data/lib/action_view/template.rb +56 -31
- data/lib/action_view/test_case.rb +50 -29
- data/lib/action_view/testing/resolvers.rb +31 -31
- data/lib/action_view/version.rb +3 -1
- data/lib/action_view/view_paths.rb +28 -34
- data/lib/action_view.rb +8 -7
- data/lib/assets/compiled/rails-ujs.js +720 -0
- metadata +25 -24
- data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "erb"
|
5
|
+
require "action_view/helpers/form_helper"
|
6
|
+
require "active_support/core_ext/string/output_safety"
|
7
|
+
require "active_support/core_ext/array/extract_options"
|
8
|
+
require "active_support/core_ext/array/wrap"
|
7
9
|
|
8
10
|
module ActionView
|
9
11
|
# = Action View Form Option Helpers
|
10
|
-
module Helpers
|
12
|
+
module Helpers #:nodoc:
|
11
13
|
# Provides a number of methods for turning different kinds of containers into a set of option tags.
|
12
14
|
#
|
13
15
|
# The <tt>collection_select</tt>, <tt>select</tt> and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter, a hash:
|
@@ -18,10 +20,10 @@ module ActionView
|
|
18
20
|
#
|
19
21
|
# could become:
|
20
22
|
#
|
21
|
-
# <select name="post[category]">
|
22
|
-
# <option></option>
|
23
|
-
# <option>joke</option>
|
24
|
-
# <option>poem</option>
|
23
|
+
# <select name="post[category]" id="post_category">
|
24
|
+
# <option value=""></option>
|
25
|
+
# <option value="joke">joke</option>
|
26
|
+
# <option value="poem">poem</option>
|
25
27
|
# </select>
|
26
28
|
#
|
27
29
|
# Another common case is a select tag for a <tt>belongs_to</tt>-associated object.
|
@@ -32,11 +34,11 @@ module ActionView
|
|
32
34
|
#
|
33
35
|
# could become:
|
34
36
|
#
|
35
|
-
# <select name="post[person_id]">
|
37
|
+
# <select name="post[person_id]" id="post_person_id">
|
36
38
|
# <option value="">None</option>
|
37
39
|
# <option value="1">David</option>
|
38
|
-
# <option value="2" selected="selected">
|
39
|
-
# <option value="3">
|
40
|
+
# <option value="2" selected="selected">Eileen</option>
|
41
|
+
# <option value="3">Rafael</option>
|
40
42
|
# </select>
|
41
43
|
#
|
42
44
|
# * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this prepends an option with a generic prompt -- "Please select" -- or the given prompt string.
|
@@ -45,11 +47,11 @@ module ActionView
|
|
45
47
|
#
|
46
48
|
# could become:
|
47
49
|
#
|
48
|
-
# <select name="post[person_id]">
|
50
|
+
# <select name="post[person_id]" id="post_person_id">
|
49
51
|
# <option value="">Select Person</option>
|
50
52
|
# <option value="1">David</option>
|
51
|
-
# <option value="2">
|
52
|
-
# <option value="3">
|
53
|
+
# <option value="2">Eileen</option>
|
54
|
+
# <option value="3">Rafael</option>
|
53
55
|
# </select>
|
54
56
|
#
|
55
57
|
# * <tt>:index</tt> - like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this
|
@@ -71,19 +73,19 @@ module ActionView
|
|
71
73
|
#
|
72
74
|
# could become:
|
73
75
|
#
|
74
|
-
# <select name="post[category]">
|
75
|
-
# <option></option>
|
76
|
-
# <option>joke</option>
|
77
|
-
# <option>poem</option>
|
78
|
-
# <option disabled="disabled">restricted</option>
|
76
|
+
# <select name="post[category]" id="post_category">
|
77
|
+
# <option value=""></option>
|
78
|
+
# <option value="joke">joke</option>
|
79
|
+
# <option value="poem">poem</option>
|
80
|
+
# <option disabled="disabled" value="restricted">restricted</option>
|
79
81
|
# </select>
|
80
82
|
#
|
81
83
|
# When used with the <tt>collection_select</tt> helper, <tt>:disabled</tt> can also be a Proc that identifies those options that should be disabled.
|
82
84
|
#
|
83
|
-
# collection_select(:post, :category_id, Category.all, :id, :name, {disabled:
|
85
|
+
# collection_select(:post, :category_id, Category.all, :id, :name, {disabled: -> (category) { category.archived? }})
|
84
86
|
#
|
85
87
|
# If the categories "2008 stuff" and "Christmas" return true when the method <tt>archived?</tt> is called, this would return:
|
86
|
-
# <select name="post[category_id]">
|
88
|
+
# <select name="post[category_id]" id="post_category_id">
|
87
89
|
# <option value="1" disabled="disabled">2008 stuff</option>
|
88
90
|
# <option value="2" disabled="disabled">Christmas</option>
|
89
91
|
# <option value="3">Jokes</option>
|
@@ -109,11 +111,11 @@ module ActionView
|
|
109
111
|
#
|
110
112
|
# would become:
|
111
113
|
#
|
112
|
-
# <select name="post[person_id]">
|
114
|
+
# <select name="post[person_id]" id="post_person_id">
|
113
115
|
# <option value=""></option>
|
114
116
|
# <option value="1" selected="selected">David</option>
|
115
|
-
# <option value="2">
|
116
|
-
# <option value="3">
|
117
|
+
# <option value="2">Eileen</option>
|
118
|
+
# <option value="3">Rafael</option>
|
117
119
|
# </select>
|
118
120
|
#
|
119
121
|
# assuming the associated person has ID 1.
|
@@ -192,7 +194,7 @@ module ActionView
|
|
192
194
|
# collection_select(:post, :author_id, Author.all, :id, :name_with_initial, prompt: true)
|
193
195
|
#
|
194
196
|
# If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return:
|
195
|
-
# <select name="post[author_id]">
|
197
|
+
# <select name="post[author_id]" id="post_author_id">
|
196
198
|
# <option value="">Please select</option>
|
197
199
|
# <option value="1" selected="selected">D. Heinemeier Hansson</option>
|
198
200
|
# <option value="2">D. Thomas</option>
|
@@ -212,9 +214,13 @@ module ActionView
|
|
212
214
|
# * +method+ - The attribute of +object+ corresponding to the select tag
|
213
215
|
# * +collection+ - An array of objects representing the <tt><optgroup></tt> tags.
|
214
216
|
# * +group_method+ - The name of a method which, when called on a member of +collection+, returns an
|
215
|
-
# array of child objects representing the <tt><option></tt> tags.
|
217
|
+
# array of child objects representing the <tt><option></tt> tags. It can also be any object that responds
|
218
|
+
# to +call+, such as a +proc+, that will be called for each member of the +collection+ to retrieve the
|
219
|
+
# value.
|
216
220
|
# * +group_label_method+ - The name of a method which, when called on a member of +collection+, returns a
|
217
|
-
# string to be used as the +label+ attribute for its <tt><optgroup></tt> tag.
|
221
|
+
# string to be used as the +label+ attribute for its <tt><optgroup></tt> tag. It can also be any object
|
222
|
+
# that responds to +call+, such as a +proc+, that will be called for each member of the +collection+ to
|
223
|
+
# retrieve the label.
|
218
224
|
# * +option_key_method+ - The name of a method which, when called on a child object of a member of
|
219
225
|
# +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
|
220
226
|
# * +option_value_method+ - The name of a method which, when called on a child object of a member of
|
@@ -243,7 +249,7 @@ module ActionView
|
|
243
249
|
#
|
244
250
|
# Possible output:
|
245
251
|
#
|
246
|
-
# <select name="city[country_id]">
|
252
|
+
# <select name="city[country_id]" id="city_country_id">
|
247
253
|
# <optgroup label="Africa">
|
248
254
|
# <option value="1">South Africa</option>
|
249
255
|
# <option value="3">Somalia</option>
|
@@ -268,25 +274,26 @@ module ActionView
|
|
268
274
|
# for more information.)
|
269
275
|
#
|
270
276
|
# You can also supply an array of ActiveSupport::TimeZone objects
|
271
|
-
# as +priority_zones
|
272
|
-
# (long) list.
|
273
|
-
#
|
274
|
-
#
|
277
|
+
# as +priority_zones+ so that they will be listed above the rest of the
|
278
|
+
# (long) list. You can use ActiveSupport::TimeZone.us_zones for a list
|
279
|
+
# of US time zones, ActiveSupport::TimeZone.country_zones(country_code)
|
280
|
+
# for another country's time zones, or a Regexp to select the zones of
|
281
|
+
# your choice.
|
275
282
|
#
|
276
283
|
# Finally, this method supports a <tt>:default</tt> option, which selects
|
277
284
|
# a default ActiveSupport::TimeZone if the object's time zone is +nil+.
|
278
285
|
#
|
279
|
-
# time_zone_select(
|
286
|
+
# time_zone_select("user", "time_zone", nil, include_blank: true)
|
280
287
|
#
|
281
|
-
# time_zone_select(
|
288
|
+
# time_zone_select("user", "time_zone", nil, default: "Pacific Time (US & Canada)")
|
282
289
|
#
|
283
|
-
# time_zone_select(
|
290
|
+
# time_zone_select("user", 'time_zone', ActiveSupport::TimeZone.us_zones, default: "Pacific Time (US & Canada)")
|
284
291
|
#
|
285
|
-
# time_zone_select(
|
292
|
+
# time_zone_select("user", 'time_zone', [ ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii'] ])
|
286
293
|
#
|
287
|
-
# time_zone_select(
|
294
|
+
# time_zone_select("user", 'time_zone', /Australia/)
|
288
295
|
#
|
289
|
-
# time_zone_select(
|
296
|
+
# time_zone_select("user", "time_zone", ActiveSupport::TimeZone.all.sort, model: ActiveSupport::TimeZone)
|
290
297
|
def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})
|
291
298
|
Tags::TimeZoneSelect.new(object, method, self, priority_zones, options, html_options).render
|
292
299
|
end
|
@@ -302,17 +309,17 @@ module ActionView
|
|
302
309
|
# # => <option value="DKK">Kroner</option>
|
303
310
|
#
|
304
311
|
# options_for_select([ "VISA", "MasterCard" ], "MasterCard")
|
305
|
-
# # => <option>VISA</option>
|
306
|
-
# # => <option selected="selected">MasterCard</option>
|
312
|
+
# # => <option value="VISA">VISA</option>
|
313
|
+
# # => <option selected="selected" value="MasterCard">MasterCard</option>
|
307
314
|
#
|
308
315
|
# options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40")
|
309
316
|
# # => <option value="$20">Basic</option>
|
310
317
|
# # => <option value="$40" selected="selected">Plus</option>
|
311
318
|
#
|
312
319
|
# options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"])
|
313
|
-
# # => <option selected="selected">VISA</option>
|
314
|
-
# # => <option>MasterCard</option>
|
315
|
-
# # => <option selected="selected">Discover</option>
|
320
|
+
# # => <option selected="selected" value="VISA">VISA</option>
|
321
|
+
# # => <option value="MasterCard">MasterCard</option>
|
322
|
+
# # => <option selected="selected" value="Discover">Discover</option>
|
316
323
|
#
|
317
324
|
# You can optionally provide HTML attributes as the last element of the array.
|
318
325
|
#
|
@@ -351,18 +358,18 @@ module ActionView
|
|
351
358
|
return container if String === container
|
352
359
|
|
353
360
|
selected, disabled = extract_selected_and_disabled(selected).map do |r|
|
354
|
-
Array(r).map
|
361
|
+
Array(r).map(&:to_s)
|
355
362
|
end
|
356
363
|
|
357
364
|
container.map do |element|
|
358
365
|
html_attributes = option_html_attributes(element)
|
359
|
-
text, value = option_text_and_value(element).map
|
366
|
+
text, value = option_text_and_value(element).map(&:to_s)
|
360
367
|
|
361
368
|
html_attributes[:selected] ||= option_value_selected?(value, selected)
|
362
369
|
html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
|
363
370
|
html_attributes[:value] = value
|
364
371
|
|
365
|
-
content_tag_string(:option, text, html_attributes)
|
372
|
+
tag_builder.content_tag_string(:option, text, html_attributes)
|
366
373
|
end.join("\n").html_safe
|
367
374
|
end
|
368
375
|
|
@@ -454,9 +461,9 @@ module ActionView
|
|
454
461
|
def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil)
|
455
462
|
collection.map do |group|
|
456
463
|
option_tags = options_from_collection_for_select(
|
457
|
-
group
|
464
|
+
value_for_collection(group, group_method), option_key_method, option_value_method, selected_key)
|
458
465
|
|
459
|
-
content_tag(
|
466
|
+
content_tag("optgroup".freeze, option_tags, label: value_for_collection(group, group_label_method))
|
460
467
|
end.join.html_safe
|
461
468
|
end
|
462
469
|
|
@@ -528,7 +535,7 @@ module ActionView
|
|
528
535
|
body = "".html_safe
|
529
536
|
|
530
537
|
if prompt
|
531
|
-
body.safe_concat content_tag(
|
538
|
+
body.safe_concat content_tag("option".freeze, prompt_text(prompt), value: "")
|
532
539
|
end
|
533
540
|
|
534
541
|
grouped_options.each do |container|
|
@@ -541,14 +548,14 @@ module ActionView
|
|
541
548
|
end
|
542
549
|
|
543
550
|
html_attributes = { label: label }.merge!(html_attributes)
|
544
|
-
body.safe_concat content_tag(
|
551
|
+
body.safe_concat content_tag("optgroup".freeze, options_for_select(container, selected_key), html_attributes)
|
545
552
|
end
|
546
553
|
|
547
554
|
body
|
548
555
|
end
|
549
556
|
|
550
557
|
# Returns a string of option tags for pretty much any time zone in the
|
551
|
-
# world. Supply
|
558
|
+
# world. Supply an ActiveSupport::TimeZone name as +selected+ to have it
|
552
559
|
# marked as the selected option tag. You can also supply an array of
|
553
560
|
# ActiveSupport::TimeZone objects as +priority_zones+, so that they will
|
554
561
|
# be listed above the rest of the (long) list. (You can use
|
@@ -556,7 +563,7 @@ module ActionView
|
|
556
563
|
# of the US time zones, or a Regexp to select the zones of your choice)
|
557
564
|
#
|
558
565
|
# The +selected+ parameter must be either +nil+, or a string that names
|
559
|
-
#
|
566
|
+
# an ActiveSupport::TimeZone.
|
560
567
|
#
|
561
568
|
# By default, +model+ is the ActiveSupport::TimeZone constant (which can
|
562
569
|
# be obtained in Active Record as a value object). The only requirement
|
@@ -577,7 +584,7 @@ module ActionView
|
|
577
584
|
end
|
578
585
|
|
579
586
|
zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
|
580
|
-
zone_options.safe_concat content_tag(
|
587
|
+
zone_options.safe_concat content_tag("option".freeze, "-------------", value: "", disabled: true)
|
581
588
|
zone_options.safe_concat "\n"
|
582
589
|
|
583
590
|
zones = zones - priority_zones
|
@@ -644,6 +651,24 @@ module ActionView
|
|
644
651
|
# collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
|
645
652
|
# b.label(:"data-value" => b.value) { b.radio_button + b.text }
|
646
653
|
# end
|
654
|
+
#
|
655
|
+
# ==== Gotcha
|
656
|
+
#
|
657
|
+
# The HTML specification says when nothing is select on a collection of radio buttons
|
658
|
+
# web browsers do not send any value to server.
|
659
|
+
# Unfortunately this introduces a gotcha:
|
660
|
+
# if a +User+ model has a +category_id+ field and in the form no category is selected, no +category_id+ parameter is sent. So,
|
661
|
+
# any strong parameters idiom like:
|
662
|
+
#
|
663
|
+
# params.require(:user).permit(...)
|
664
|
+
#
|
665
|
+
# will raise an error since no <tt>{user: ...}</tt> will be present.
|
666
|
+
#
|
667
|
+
# To prevent this the helper generates an auxiliary hidden field before
|
668
|
+
# every collection of radio buttons. The hidden field has the same name as collection radio button and blank value.
|
669
|
+
#
|
670
|
+
# In case if you don't want the helper to generate this hidden field you can specify
|
671
|
+
# <tt>include_hidden: false</tt> option.
|
647
672
|
def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
648
673
|
Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
649
674
|
end
|
@@ -707,6 +732,27 @@ module ActionView
|
|
707
732
|
# collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
708
733
|
# b.label(:"data-value" => b.value) { b.check_box + b.text }
|
709
734
|
# end
|
735
|
+
#
|
736
|
+
# ==== Gotcha
|
737
|
+
#
|
738
|
+
# When no selection is made for a collection of checkboxes most
|
739
|
+
# web browsers will not send any value.
|
740
|
+
#
|
741
|
+
# For example, if we have a +User+ model with +category_ids+ field and we
|
742
|
+
# have the following code in our update action:
|
743
|
+
#
|
744
|
+
# @user.update(params[:user])
|
745
|
+
#
|
746
|
+
# If no +category_ids+ are selected then we can safely assume this field
|
747
|
+
# will not be updated.
|
748
|
+
#
|
749
|
+
# This is possible thanks to a hidden field generated by the helper method
|
750
|
+
# for every collection of checkboxes.
|
751
|
+
# This hidden field is given the same field name as the checkboxes with a
|
752
|
+
# blank value.
|
753
|
+
#
|
754
|
+
# In the rare case you don't want this hidden field, you can pass the
|
755
|
+
# <tt>include_hidden: false</tt> option to the helper method.
|
710
756
|
def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
711
757
|
Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
712
758
|
end
|
@@ -760,7 +806,7 @@ module ActionView
|
|
760
806
|
end
|
761
807
|
|
762
808
|
def prompt_text(prompt)
|
763
|
-
prompt.kind_of?(String) ? prompt : I18n.translate(
|
809
|
+
prompt.kind_of?(String) ? prompt : I18n.translate("helpers.select.prompt", default: "Please select")
|
764
810
|
end
|
765
811
|
end
|
766
812
|
|
@@ -774,7 +820,7 @@ module ActionView
|
|
774
820
|
#
|
775
821
|
# Please refer to the documentation of the base helper for details.
|
776
822
|
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
777
|
-
@template.select(@object_name, method, choices, objectify_options(options), @
|
823
|
+
@template.select(@object_name, method, choices, objectify_options(options), @default_html_options.merge(html_options), &block)
|
778
824
|
end
|
779
825
|
|
780
826
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_select for form builders:
|
@@ -786,7 +832,7 @@ module ActionView
|
|
786
832
|
#
|
787
833
|
# Please refer to the documentation of the base helper for details.
|
788
834
|
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
789
|
-
@template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @
|
835
|
+
@template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options))
|
790
836
|
end
|
791
837
|
|
792
838
|
# Wraps ActionView::Helpers::FormOptionsHelper#grouped_collection_select for form builders:
|
@@ -798,7 +844,7 @@ module ActionView
|
|
798
844
|
#
|
799
845
|
# Please refer to the documentation of the base helper for details.
|
800
846
|
def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
801
|
-
@template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @
|
847
|
+
@template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_html_options.merge(html_options))
|
802
848
|
end
|
803
849
|
|
804
850
|
# Wraps ActionView::Helpers::FormOptionsHelper#time_zone_select for form builders:
|
@@ -810,7 +856,7 @@ module ActionView
|
|
810
856
|
#
|
811
857
|
# Please refer to the documentation of the base helper for details.
|
812
858
|
def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
|
813
|
-
@template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @
|
859
|
+
@template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_html_options.merge(html_options))
|
814
860
|
end
|
815
861
|
|
816
862
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_check_boxes for form builders:
|
@@ -822,7 +868,7 @@ module ActionView
|
|
822
868
|
#
|
823
869
|
# Please refer to the documentation of the base helper for details.
|
824
870
|
def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
825
|
-
@template.collection_check_boxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @
|
871
|
+
@template.collection_check_boxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
|
826
872
|
end
|
827
873
|
|
828
874
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_radio_buttons for form builders:
|
@@ -834,7 +880,7 @@ module ActionView
|
|
834
880
|
#
|
835
881
|
# Please refer to the documentation of the base helper for details.
|
836
882
|
def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
837
|
-
@template.collection_radio_buttons(@object_name, method, collection, value_method, text_method, objectify_options(options), @
|
883
|
+
@template.collection_radio_buttons(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
|
838
884
|
end
|
839
885
|
end
|
840
886
|
end
|