actionview 7.2.3 → 8.1.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 +112 -121
- data/lib/action_view/base.rb +5 -2
- data/lib/action_view/buffers.rb +1 -1
- data/lib/action_view/dependency_tracker/erb_tracker.rb +37 -28
- 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 +7 -1
- data/lib/action_view/gem_version.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +21 -2
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -2
- data/lib/action_view/helpers/cache_helper.rb +8 -0
- data/lib/action_view/helpers/capture_helper.rb +2 -2
- data/lib/action_view/helpers/controller_helper.rb +6 -2
- data/lib/action_view/helpers/date_helper.rb +20 -3
- data/lib/action_view/helpers/form_helper.rb +76 -76
- data/lib/action_view/helpers/form_options_helper.rb +33 -32
- data/lib/action_view/helpers/form_tag_helper.rb +35 -25
- data/lib/action_view/helpers/javascript_helper.rb +5 -1
- data/lib/action_view/helpers/number_helper.rb +14 -0
- 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 +62 -75
- data/lib/action_view/helpers/tags/base.rb +11 -9
- data/lib/action_view/helpers/tags/check_box.rb +9 -3
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
- data/lib/action_view/helpers/tags/datetime_field.rb +1 -1
- data/lib/action_view/helpers/tags/file_field.rb +7 -2
- data/lib/action_view/helpers/tags/hidden_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.rb +6 -1
- data/lib/action_view/helpers/tags/select_renderer.rb +6 -4
- 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/translation_helper.rb +6 -1
- data/lib/action_view/helpers/url_helper.rb +39 -13
- data/lib/action_view/layouts.rb +1 -1
- data/lib/action_view/locale/en.yml +3 -0
- data/lib/action_view/log_subscriber.rb +1 -4
- data/lib/action_view/railtie.rb +12 -1
- data/lib/action_view/record_identifier.rb +22 -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/collection_caching.rb +5 -1
- data/lib/action_view/renderer/partial_renderer.rb +16 -0
- data/lib/action_view/renderer/streaming_template_renderer.rb +8 -2
- data/lib/action_view/rendering.rb +2 -3
- data/lib/action_view/structured_event_subscriber.rb +97 -0
- data/lib/action_view/template/error.rb +7 -3
- data/lib/action_view/template/handlers/erb/erubi.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +37 -12
- 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 +9 -4
- data/lib/action_view/test_case.rb +50 -52
- data/lib/action_view.rb +3 -0
- metadata +14 -26
|
@@ -93,6 +93,14 @@ module ActionView
|
|
|
93
93
|
# render partial: 'attachments/attachment', collection: group_of_attachments
|
|
94
94
|
# render partial: 'documents/document', collection: @project.documents.where(published: true).order('created_at')
|
|
95
95
|
#
|
|
96
|
+
# One last type of dependency can be determined implicitly:
|
|
97
|
+
#
|
|
98
|
+
# render "maintenance_tasks/runs/info/#{run.status}"
|
|
99
|
+
#
|
|
100
|
+
# Because the value passed to render ends in interpolation, Action View
|
|
101
|
+
# will mark all partials within the "maintenance_tasks/runs/info" folder as
|
|
102
|
+
# dependencies.
|
|
103
|
+
#
|
|
96
104
|
# === Explicit dependencies
|
|
97
105
|
#
|
|
98
106
|
# Sometimes you'll have template dependencies that can't be derived at all. This is typically
|
|
@@ -44,10 +44,10 @@ module ActionView
|
|
|
44
44
|
#
|
|
45
45
|
# @greeting # => "Welcome to my shiny new web page! The date and time is 2018-09-06 11:09:16 -0500"
|
|
46
46
|
#
|
|
47
|
-
def capture(
|
|
47
|
+
def capture(*, **, &block)
|
|
48
48
|
value = nil
|
|
49
49
|
@output_buffer ||= ActionView::OutputBuffer.new
|
|
50
|
-
buffer = @output_buffer.capture { value = yield(
|
|
50
|
+
buffer = @output_buffer.capture { value = yield(*, **) }
|
|
51
51
|
|
|
52
52
|
string = if @output_buffer.equal?(value)
|
|
53
53
|
buffer
|
|
@@ -20,11 +20,15 @@ module ActionView
|
|
|
20
20
|
def assign_controller(controller)
|
|
21
21
|
if @_controller = controller
|
|
22
22
|
@_request = controller.request if controller.respond_to?(:request)
|
|
23
|
-
|
|
23
|
+
if controller.respond_to?(:config)
|
|
24
|
+
@_config = controller.config.inheritable_copy
|
|
25
|
+
else
|
|
26
|
+
@_config = ActiveSupport::InheritableOptions.new
|
|
27
|
+
end
|
|
24
28
|
@_default_form_builder = controller.default_form_builder if controller.respond_to?(:default_form_builder)
|
|
25
29
|
else
|
|
26
30
|
@_request ||= nil
|
|
27
|
-
@_config
|
|
31
|
+
@_config = ActiveSupport::InheritableOptions.new
|
|
28
32
|
@_default_form_builder ||= nil
|
|
29
33
|
end
|
|
30
34
|
end
|
|
@@ -186,6 +186,23 @@ module ActionView
|
|
|
186
186
|
|
|
187
187
|
alias_method :distance_of_time_in_words_to_now, :time_ago_in_words
|
|
188
188
|
|
|
189
|
+
# Like <tt>time_ago_in_words</tt>, but adds a prefix/suffix depending on whether the time is in the past or future.
|
|
190
|
+
# You can use the <tt>scope</tt> option to customize the translation scope. All other options
|
|
191
|
+
# are forwarded to <tt>time_ago_in_words</tt>.
|
|
192
|
+
#
|
|
193
|
+
# relative_time_in_words(3.minutes.from_now) # => "in 3 minutes"
|
|
194
|
+
# relative_time_in_words(3.minutes.ago) # => "3 minutes ago"
|
|
195
|
+
# relative_time_in_words(10.seconds.ago, include_seconds: true) # => "less than 10 seconds ago"
|
|
196
|
+
#
|
|
197
|
+
# See also #time_ago_in_words
|
|
198
|
+
def relative_time_in_words(from_time, options = {})
|
|
199
|
+
now = Time.now
|
|
200
|
+
time = distance_of_time_in_words(from_time, now, options.except(:scope))
|
|
201
|
+
key = from_time > now ? :future : :past
|
|
202
|
+
|
|
203
|
+
I18n.t(key, time: time, scope: options.fetch(:scope, :'datetime.relative'), locale: options[:locale])
|
|
204
|
+
end
|
|
205
|
+
|
|
189
206
|
# Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based
|
|
190
207
|
# attribute (identified by +method+) on an object assigned to the template (identified by +object+).
|
|
191
208
|
#
|
|
@@ -1235,7 +1252,7 @@ module ActionView
|
|
|
1235
1252
|
class FormBuilder
|
|
1236
1253
|
# Wraps ActionView::Helpers::DateHelper#date_select for form builders:
|
|
1237
1254
|
#
|
|
1238
|
-
# <%=
|
|
1255
|
+
# <%= form_with model: @person do |f| %>
|
|
1239
1256
|
# <%= f.date_select :birth_date %>
|
|
1240
1257
|
# <%= f.submit %>
|
|
1241
1258
|
# <% end %>
|
|
@@ -1247,7 +1264,7 @@ module ActionView
|
|
|
1247
1264
|
|
|
1248
1265
|
# Wraps ActionView::Helpers::DateHelper#time_select for form builders:
|
|
1249
1266
|
#
|
|
1250
|
-
# <%=
|
|
1267
|
+
# <%= form_with model: @race do |f| %>
|
|
1251
1268
|
# <%= f.time_select :average_lap %>
|
|
1252
1269
|
# <%= f.submit %>
|
|
1253
1270
|
# <% end %>
|
|
@@ -1259,7 +1276,7 @@ module ActionView
|
|
|
1259
1276
|
|
|
1260
1277
|
# Wraps ActionView::Helpers::DateHelper#datetime_select for form builders:
|
|
1261
1278
|
#
|
|
1262
|
-
# <%=
|
|
1279
|
+
# <%= form_with model: @person do |f| %>
|
|
1263
1280
|
# <%= f.datetime_select :last_request_at %>
|
|
1264
1281
|
# <%= f.submit %>
|
|
1265
1282
|
# <% end %>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "cgi"
|
|
4
3
|
require "action_view/helpers/date_helper"
|
|
5
4
|
require "action_view/helpers/url_helper"
|
|
6
5
|
require "action_view/helpers/form_tag_helper"
|
|
@@ -30,20 +29,21 @@ module ActionView
|
|
|
30
29
|
# when the form is initially displayed, input fields corresponding to attributes
|
|
31
30
|
# of the resource should show the current values of those attributes.
|
|
32
31
|
#
|
|
33
|
-
# In \Rails, this is usually achieved by creating the form using
|
|
34
|
-
# a number of related helper methods.
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
32
|
+
# In \Rails, this is usually achieved by creating the form using either
|
|
33
|
+
# #form_with or #form_for and a number of related helper methods. These
|
|
34
|
+
# methods generate an appropriate <tt>form</tt> tag and yield a form
|
|
35
|
+
# builder object that knows the model the form is about. Input fields are
|
|
36
|
+
# created by calling methods defined on the form builder, which means they
|
|
37
|
+
# are able to generate the appropriate names and default values
|
|
38
38
|
# 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.
|
|
39
|
+
# Conventions in the generated field names allow controllers to receive form
|
|
40
|
+
# data nicely structured in +params+ with no effort on your side.
|
|
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_with or #form_for:
|
|
45
45
|
#
|
|
46
|
-
# <%=
|
|
46
|
+
# <%= form_with model: @person do |f| %>
|
|
47
47
|
# <%= f.label :first_name %>:
|
|
48
48
|
# <%= f.text_field :first_name %><br />
|
|
49
49
|
#
|
|
@@ -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.
|
|
136
|
-
# Admin? : <%= f.
|
|
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 : <%=
|
|
203
|
-
# 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
|
#
|
|
@@ -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.
|
|
393
|
-
# <%= f.
|
|
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
|
-
# <%=
|
|
672
|
-
# <%=
|
|
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.
|
|
734
|
-
# <%= form.
|
|
733
|
+
# <%= form.textarea :biography %>
|
|
734
|
+
# <%= form.checkbox :admin %>
|
|
735
735
|
# <%= form.submit %>
|
|
736
736
|
# <% end %>
|
|
737
737
|
#
|
|
@@ -753,7 +753,7 @@ module ActionView
|
|
|
753
753
|
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
|
|
754
754
|
# end
|
|
755
755
|
def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block)
|
|
756
|
-
|
|
756
|
+
raise ArgumentError, "Passed nil to the :model argument, expect an object or false" if model.nil?
|
|
757
757
|
|
|
758
758
|
options = { allow_method_names_outside_object: true, skip_default_ids: !form_with_generates_ids }.merge!(options)
|
|
759
759
|
|
|
@@ -784,8 +784,8 @@ module ActionView
|
|
|
784
784
|
end
|
|
785
785
|
|
|
786
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.
|
|
787
|
+
# doesn't create the form tags themselves. This makes +fields_for+
|
|
788
|
+
# suitable for specifying additional model objects in the same form.
|
|
789
789
|
#
|
|
790
790
|
# Although the usage and purpose of +fields_for+ is similar to #form_with's,
|
|
791
791
|
# its method signature is slightly different. Like #form_with, it yields
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
|
@@ -914,7 +914,7 @@ module ActionView
|
|
|
914
914
|
# ...
|
|
915
915
|
# <%= person_form.fields_for :address do |address_fields| %>
|
|
916
916
|
# ...
|
|
917
|
-
# Delete: <%= address_fields.
|
|
917
|
+
# Delete: <%= address_fields.checkbox :_destroy %>
|
|
918
918
|
# <% end %>
|
|
919
919
|
# ...
|
|
920
920
|
# <% end %>
|
|
@@ -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.
|
|
1005
|
+
# Delete: <%= project_fields.checkbox :_destroy %>
|
|
1006
1006
|
# <% end %>
|
|
1007
1007
|
# ...
|
|
1008
1008
|
# <% end %>
|
|
@@ -1069,8 +1069,8 @@ module ActionView
|
|
|
1069
1069
|
# <%= fields model: @comment do |fields| %>
|
|
1070
1070
|
# <%= fields.text_field :body %>
|
|
1071
1071
|
#
|
|
1072
|
-
# <%=
|
|
1073
|
-
# <%=
|
|
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
|
|
@@ -1255,28 +1255,29 @@ module ActionView
|
|
|
1255
1255
|
# hash with +options+.
|
|
1256
1256
|
#
|
|
1257
1257
|
# ==== Examples
|
|
1258
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
|
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.
|
|
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#
|
|
1328
|
+
# In that case it is preferable to either use FormTagHelper#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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
|
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,18 @@ 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
|
|
1634
|
+
# +FormBuilder+ object is yielded when using
|
|
1635
|
+
# {form_with}[rdof-ref:ActionView::Helpers::FormHelper#form_with] or #fields_for.
|
|
1633
1636
|
# For example:
|
|
1634
1637
|
#
|
|
1635
1638
|
# <%= form_with model: @person do |person_form| %>
|
|
1636
1639
|
# Name: <%= person_form.text_field :name %>
|
|
1637
|
-
# Admin: <%= person_form.
|
|
1640
|
+
# Admin: <%= person_form.checkbox :admin %>
|
|
1638
1641
|
# <% end %>
|
|
1639
1642
|
#
|
|
1640
1643
|
# In the above block, a +FormBuilder+ object is yielded as the
|
|
1641
1644
|
# +person_form+ variable. This allows you to generate the +text_field+
|
|
1642
|
-
# and +
|
|
1645
|
+
# and +checkbox+ fields by specifying their eponymous methods, which
|
|
1643
1646
|
# modify the underlying template and associates the <tt>@person</tt> model object
|
|
1644
1647
|
# with the form.
|
|
1645
1648
|
#
|
|
@@ -1681,7 +1684,7 @@ module ActionView
|
|
|
1681
1684
|
# The methods which wrap a form helper call.
|
|
1682
1685
|
class_attribute :field_helpers, default: [
|
|
1683
1686
|
:fields_for, :fields, :label, :text_field, :password_field,
|
|
1684
|
-
:hidden_field, :file_field, :
|
|
1687
|
+
:hidden_field, :file_field, :textarea, :checkbox,
|
|
1685
1688
|
:radio_button, :color_field, :search_field,
|
|
1686
1689
|
:telephone_field, :phone_field, :date_field,
|
|
1687
1690
|
:time_field, :datetime_field, :datetime_local_field,
|
|
@@ -1824,14 +1827,14 @@ module ActionView
|
|
|
1824
1827
|
# Please refer to the documentation of the base helper for details.
|
|
1825
1828
|
|
|
1826
1829
|
##
|
|
1827
|
-
# :method:
|
|
1830
|
+
# :method: textarea
|
|
1828
1831
|
#
|
|
1829
|
-
# :call-seq:
|
|
1832
|
+
# :call-seq: textarea(method, options = {})
|
|
1830
1833
|
#
|
|
1831
|
-
# Wraps ActionView::Helpers::FormHelper#
|
|
1834
|
+
# Wraps ActionView::Helpers::FormHelper#textarea for form builders:
|
|
1832
1835
|
#
|
|
1833
1836
|
# <%= form_with model: @user do |f| %>
|
|
1834
|
-
# <%= f.
|
|
1837
|
+
# <%= f.textarea :detail %>
|
|
1835
1838
|
# <% end %>
|
|
1836
1839
|
#
|
|
1837
1840
|
# Please refer to the documentation of the base helper for details.
|
|
@@ -2019,24 +2022,20 @@ module ActionView
|
|
|
2019
2022
|
# Please refer to the documentation of the base helper for details.
|
|
2020
2023
|
|
|
2021
2024
|
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
|
|
2025
|
+
(field_helpers - [:label, :checkbox, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
|
|
2026
|
+
code_generator.class_eval do |batch|
|
|
2027
|
+
batch <<
|
|
2028
|
+
"def #{selector}(method, options = {})" <<
|
|
2029
|
+
" @template.#{selector}(@object_name, method, objectify_options(options))" <<
|
|
2030
|
+
"end"
|
|
2031
|
+
end
|
|
2033
2032
|
end
|
|
2034
|
-
end
|
|
2035
2033
|
end
|
|
2034
|
+
alias_method :text_area, :textarea
|
|
2036
2035
|
|
|
2037
2036
|
# 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
|
+
# doesn't create the form tags themselves. This makes +fields_for+
|
|
2038
|
+
# suitable for specifying additional model objects in the same form.
|
|
2040
2039
|
#
|
|
2041
2040
|
# Although the usage and purpose of +fields_for+ is similar to #form_with's,
|
|
2042
2041
|
# its method signature is slightly different. Like #form_with, it yields
|
|
@@ -2055,7 +2054,7 @@ module ActionView
|
|
|
2055
2054
|
# Last name : <%= person_form.text_field :last_name %>
|
|
2056
2055
|
#
|
|
2057
2056
|
# <%= fields_for :permission, @person.permission do |permission_fields| %>
|
|
2058
|
-
# Admin? : <%= permission_fields.
|
|
2057
|
+
# Admin? : <%= permission_fields.checkbox :admin %>
|
|
2059
2058
|
# <% end %>
|
|
2060
2059
|
#
|
|
2061
2060
|
# <%= person_form.submit %>
|
|
@@ -2072,7 +2071,7 @@ module ActionView
|
|
|
2072
2071
|
# object to +fields_for+ -
|
|
2073
2072
|
#
|
|
2074
2073
|
# <%= fields_for :permission do |permission_fields| %>
|
|
2075
|
-
# Admin?: <%= permission_fields.
|
|
2074
|
+
# Admin?: <%= permission_fields.checkbox :admin %>
|
|
2076
2075
|
# <% end %>
|
|
2077
2076
|
#
|
|
2078
2077
|
# ...in which case, if <tt>:permission</tt> also happens to be the name of an
|
|
@@ -2084,7 +2083,7 @@ module ActionView
|
|
|
2084
2083
|
# name has been omitted) -
|
|
2085
2084
|
#
|
|
2086
2085
|
# <%= fields_for @person.permission do |permission_fields| %>
|
|
2087
|
-
# Admin?: <%= permission_fields.
|
|
2086
|
+
# Admin?: <%= permission_fields.checkbox :admin %>
|
|
2088
2087
|
# <% end %>
|
|
2089
2088
|
#
|
|
2090
2089
|
# and +fields_for+ will derive the required name of the field from the
|
|
@@ -2102,7 +2101,7 @@ module ActionView
|
|
|
2102
2101
|
# <%= form_with model: @person do |person_form| %>
|
|
2103
2102
|
# ...
|
|
2104
2103
|
# <%= fields_for :permission, @person.permission, {} do |permission_fields| %>
|
|
2105
|
-
# Admin?: <%=
|
|
2104
|
+
# Admin?: <%= checkbox_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
|
|
2106
2105
|
# <% end %>
|
|
2107
2106
|
# ...
|
|
2108
2107
|
# <% end %>
|
|
@@ -2177,7 +2176,7 @@ module ActionView
|
|
|
2177
2176
|
# ...
|
|
2178
2177
|
# <%= person_form.fields_for :address do |address_fields| %>
|
|
2179
2178
|
# ...
|
|
2180
|
-
# Delete: <%= address_fields.
|
|
2179
|
+
# Delete: <%= address_fields.checkbox :_destroy %>
|
|
2181
2180
|
# <% end %>
|
|
2182
2181
|
# ...
|
|
2183
2182
|
# <% end %>
|
|
@@ -2265,7 +2264,7 @@ module ActionView
|
|
|
2265
2264
|
# <%= form_with model: @person do |person_form| %>
|
|
2266
2265
|
# ...
|
|
2267
2266
|
# <%= person_form.fields_for :projects do |project_fields| %>
|
|
2268
|
-
# Delete: <%= project_fields.
|
|
2267
|
+
# Delete: <%= project_fields.checkbox :_destroy %>
|
|
2269
2268
|
# <% end %>
|
|
2270
2269
|
# ...
|
|
2271
2270
|
# <% end %>
|
|
@@ -2444,7 +2443,7 @@ module ActionView
|
|
|
2444
2443
|
# within an array-like parameter, as in
|
|
2445
2444
|
#
|
|
2446
2445
|
# <%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
|
|
2447
|
-
# <%= form.
|
|
2446
|
+
# <%= form.checkbox :paid %>
|
|
2448
2447
|
# ...
|
|
2449
2448
|
# <% end %>
|
|
2450
2449
|
#
|
|
@@ -2452,28 +2451,29 @@ module ActionView
|
|
|
2452
2451
|
# the elements of the array. For each item with a checked check box you
|
|
2453
2452
|
# get an extra ghost item with only that attribute, assigned to "0".
|
|
2454
2453
|
#
|
|
2455
|
-
# In that case it is preferable to either use FormTagHelper#
|
|
2454
|
+
# In that case it is preferable to either use FormTagHelper#checkbox_tag or to use
|
|
2456
2455
|
# hashes instead of arrays.
|
|
2457
2456
|
#
|
|
2458
2457
|
# ==== Examples
|
|
2459
2458
|
#
|
|
2460
2459
|
# # Let's say that @article.validated? is 1:
|
|
2461
|
-
#
|
|
2460
|
+
# checkbox("validated")
|
|
2462
2461
|
# # => <input name="article[validated]" type="hidden" value="0" />
|
|
2463
2462
|
# # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
|
|
2464
2463
|
#
|
|
2465
2464
|
# # Let's say that @puppy.gooddog is "no":
|
|
2466
|
-
#
|
|
2465
|
+
# checkbox("gooddog", {}, "yes", "no")
|
|
2467
2466
|
# # => <input name="puppy[gooddog]" type="hidden" value="no" />
|
|
2468
2467
|
# # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
|
|
2469
2468
|
#
|
|
2470
2469
|
# # Let's say that @eula.accepted is "no":
|
|
2471
|
-
#
|
|
2470
|
+
# checkbox("accepted", { class: 'eula_check' }, "yes", "no")
|
|
2472
2471
|
# # => <input name="eula[accepted]" type="hidden" value="no" />
|
|
2473
2472
|
# # <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />
|
|
2474
|
-
def
|
|
2475
|
-
@template.
|
|
2473
|
+
def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0")
|
|
2474
|
+
@template.checkbox(@object_name, method, objectify_options(options), checked_value, unchecked_value)
|
|
2476
2475
|
end
|
|
2476
|
+
alias_method :check_box, :checkbox
|
|
2477
2477
|
|
|
2478
2478
|
# Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
|
|
2479
2479
|
# assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
|