actionview 7.2.2 → 8.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -114
- data/lib/action_view/dependency_tracker/erb_tracker.rb +35 -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/gem_version.rb +4 -4
- data/lib/action_view/helpers/cache_helper.rb +8 -0
- data/lib/action_view/helpers/form_helper.rb +59 -60
- data/lib/action_view/helpers/form_options_helper.rb +16 -14
- data/lib/action_view/helpers/form_tag_helper.rb +18 -16
- data/lib/action_view/helpers/rendering_helper.rb +160 -50
- data/lib/action_view/helpers/tag_helper.rb +41 -38
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
- data/lib/action_view/helpers/text_helper.rb +1 -1
- data/lib/action_view/helpers/url_helper.rb +2 -4
- data/lib/action_view/layouts.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/streaming_template_renderer.rb +0 -1
- data/lib/action_view/rendering.rb +2 -3
- data/lib/action_view/template/resolver.rb +0 -1
- data/lib/action_view/template.rb +3 -14
- metadata +13 -12
@@ -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
|
#
|
@@ -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 +
|
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
|
-
#
|
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
|
@@ -1634,12 +1636,12 @@ module ActionView
|
|
1634
1636
|
#
|
1635
1637
|
# <%= form_with model: @person do |person_form| %>
|
1636
1638
|
# Name: <%= person_form.text_field :name %>
|
1637
|
-
# Admin: <%= person_form.
|
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 +
|
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, :
|
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,
|
@@ -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:
|
1829
|
+
# :method: textarea
|
1828
1830
|
#
|
1829
|
-
# :call-seq:
|
1831
|
+
# :call-seq: textarea(method, options = {})
|
1830
1832
|
#
|
1831
|
-
# Wraps ActionView::Helpers::FormHelper#
|
1833
|
+
# Wraps ActionView::Helpers::FormHelper#textarea for form builders:
|
1832
1834
|
#
|
1833
1835
|
# <%= form_with model: @user do |f| %>
|
1834
|
-
# <%= f.
|
1836
|
+
# <%= f.textarea :detail %>
|
1835
1837
|
# <% end %>
|
1836
1838
|
#
|
1837
1839
|
# Please refer to the documentation of the base helper for details.
|
@@ -2019,20 +2021,16 @@ 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, :
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
@template
|
2027
|
-
|
2028
|
-
|
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
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
|
@@ -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.
|
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.
|
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.
|
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?: <%=
|
2103
|
+
# Admin?: <%= checkbox_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
|
2106
2104
|
# <% end %>
|
2107
2105
|
# ...
|
2108
2106
|
# <% end %>
|
@@ -2177,7 +2175,7 @@ module ActionView
|
|
2177
2175
|
# ...
|
2178
2176
|
# <%= person_form.fields_for :address do |address_fields| %>
|
2179
2177
|
# ...
|
2180
|
-
# Delete: <%= address_fields.
|
2178
|
+
# Delete: <%= address_fields.checkbox :_destroy %>
|
2181
2179
|
# <% end %>
|
2182
2180
|
# ...
|
2183
2181
|
# <% end %>
|
@@ -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.
|
2266
|
+
# Delete: <%= project_fields.checkbox :_destroy %>
|
2269
2267
|
# <% end %>
|
2270
2268
|
# ...
|
2271
2269
|
# <% end %>
|
@@ -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.
|
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 +
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
2475
|
-
@template.
|
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
|
@@ -686,7 +686,7 @@ module ActionView
|
|
686
686
|
# if a +User+ model has a +category_id+ field and in the form no category is selected, no +category_id+ parameter is sent. So,
|
687
687
|
# any strong parameters idiom like:
|
688
688
|
#
|
689
|
-
# params.
|
689
|
+
# params.expect(user: [...])
|
690
690
|
#
|
691
691
|
# will raise an error since no <tt>{user: ...}</tt> will be present.
|
692
692
|
#
|
@@ -723,7 +723,7 @@ module ActionView
|
|
723
723
|
# end
|
724
724
|
#
|
725
725
|
# Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
|
726
|
-
#
|
726
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial)
|
727
727
|
#
|
728
728
|
# If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return:
|
729
729
|
# <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
|
@@ -736,8 +736,8 @@ module ActionView
|
|
736
736
|
#
|
737
737
|
# It is also possible to customize the way the elements will be shown by
|
738
738
|
# giving a block to the method:
|
739
|
-
#
|
740
|
-
# b.label { b.
|
739
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
740
|
+
# b.label { b.checkbox }
|
741
741
|
# end
|
742
742
|
#
|
743
743
|
# The argument passed to the block is a special kind of builder for this
|
@@ -746,17 +746,17 @@ module ActionView
|
|
746
746
|
# Using it, you can change the label and check box display order or even
|
747
747
|
# use the label as wrapper, as in the example above.
|
748
748
|
#
|
749
|
-
# The builder methods <tt>label</tt> and <tt>
|
749
|
+
# The builder methods <tt>label</tt> and <tt>checkbox</tt> also accept
|
750
750
|
# extra HTML options:
|
751
|
-
#
|
752
|
-
# b.label(class: "
|
751
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
752
|
+
# b.label(class: "checkbox") { b.checkbox(class: "checkbox") }
|
753
753
|
# end
|
754
754
|
#
|
755
755
|
# There are also three special methods available: <tt>object</tt>, <tt>text</tt> and
|
756
756
|
# <tt>value</tt>, which are the current item being rendered, its text and value methods,
|
757
757
|
# respectively. You can use them like this:
|
758
|
-
#
|
759
|
-
# b.label(:"data-value" => b.value) { b.
|
758
|
+
# collection_checkboxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
|
759
|
+
# b.label(:"data-value" => b.value) { b.checkbox + b.text }
|
760
760
|
# end
|
761
761
|
#
|
762
762
|
# ==== Gotcha
|
@@ -779,9 +779,10 @@ module ActionView
|
|
779
779
|
#
|
780
780
|
# In the rare case you don't want this hidden field, you can pass the
|
781
781
|
# <tt>include_hidden: false</tt> option to the helper method.
|
782
|
-
def
|
782
|
+
def collection_checkboxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
783
783
|
Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
784
784
|
end
|
785
|
+
alias_method :collection_check_boxes, :collection_checkboxes
|
785
786
|
|
786
787
|
private
|
787
788
|
def option_html_attributes(element)
|
@@ -897,17 +898,18 @@ module ActionView
|
|
897
898
|
@template.weekday_select(@object_name, method, objectify_options(options), @default_html_options.merge(html_options))
|
898
899
|
end
|
899
900
|
|
900
|
-
# Wraps ActionView::Helpers::FormOptionsHelper#
|
901
|
+
# Wraps ActionView::Helpers::FormOptionsHelper#collection_checkboxes for form builders:
|
901
902
|
#
|
902
903
|
# <%= form_for @post do |f| %>
|
903
|
-
# <%= f.
|
904
|
+
# <%= f.collection_checkboxes :author_ids, Author.all, :id, :name_with_initial %>
|
904
905
|
# <%= f.submit %>
|
905
906
|
# <% end %>
|
906
907
|
#
|
907
908
|
# Please refer to the documentation of the base helper for details.
|
908
|
-
def
|
909
|
-
@template.
|
909
|
+
def collection_checkboxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
910
|
+
@template.collection_checkboxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_html_options.merge(html_options), &block)
|
910
911
|
end
|
912
|
+
alias_method :collection_check_boxes, :collection_checkboxes
|
911
913
|
|
912
914
|
# Wraps ActionView::Helpers::FormOptionsHelper#collection_radio_buttons for form builders:
|
913
915
|
#
|
@@ -393,24 +393,24 @@ module ActionView
|
|
393
393
|
# * Any other key creates standard HTML attributes for the tag.
|
394
394
|
#
|
395
395
|
# ==== Examples
|
396
|
-
#
|
396
|
+
# textarea_tag 'post'
|
397
397
|
# # => <textarea id="post" name="post"></textarea>
|
398
398
|
#
|
399
|
-
#
|
399
|
+
# textarea_tag 'bio', @user.bio
|
400
400
|
# # => <textarea id="bio" name="bio">This is my biography.</textarea>
|
401
401
|
#
|
402
|
-
#
|
402
|
+
# textarea_tag 'body', nil, rows: 10, cols: 25
|
403
403
|
# # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
|
404
404
|
#
|
405
|
-
#
|
405
|
+
# textarea_tag 'body', nil, size: "25x10"
|
406
406
|
# # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
|
407
407
|
#
|
408
|
-
#
|
408
|
+
# textarea_tag 'description', "Description goes here.", disabled: true
|
409
409
|
# # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
|
410
410
|
#
|
411
|
-
#
|
411
|
+
# textarea_tag 'comment', nil, class: 'comment_input'
|
412
412
|
# # => <textarea class="comment_input" id="comment" name="comment"></textarea>
|
413
|
-
def
|
413
|
+
def textarea_tag(name, content = nil, options = {})
|
414
414
|
options = options.stringify_keys
|
415
415
|
|
416
416
|
if size = options.delete("size")
|
@@ -422,12 +422,13 @@ module ActionView
|
|
422
422
|
|
423
423
|
content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)
|
424
424
|
end
|
425
|
+
alias_method :text_area_tag, :textarea_tag
|
425
426
|
|
426
427
|
##
|
427
428
|
# :call-seq:
|
428
|
-
#
|
429
|
-
#
|
430
|
-
#
|
429
|
+
# checkbox_tag(name, options = {})
|
430
|
+
# checkbox_tag(name, value, options = {})
|
431
|
+
# checkbox_tag(name, value, checked, options = {})
|
431
432
|
#
|
432
433
|
# Creates a check box form input tag.
|
433
434
|
#
|
@@ -438,21 +439,21 @@ module ActionView
|
|
438
439
|
# * Any other key creates standard HTML options for the tag.
|
439
440
|
#
|
440
441
|
# ==== Examples
|
441
|
-
#
|
442
|
+
# checkbox_tag 'accept'
|
442
443
|
# # => <input id="accept" name="accept" type="checkbox" value="1" />
|
443
444
|
#
|
444
|
-
#
|
445
|
+
# checkbox_tag 'rock', 'rock music'
|
445
446
|
# # => <input id="rock" name="rock" type="checkbox" value="rock music" />
|
446
447
|
#
|
447
|
-
#
|
448
|
+
# checkbox_tag 'receive_email', 'yes', true
|
448
449
|
# # => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />
|
449
450
|
#
|
450
|
-
#
|
451
|
+
# checkbox_tag 'tos', 'yes', false, class: 'accept_tos'
|
451
452
|
# # => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />
|
452
453
|
#
|
453
|
-
#
|
454
|
+
# checkbox_tag 'eula', 'accepted', false, disabled: true
|
454
455
|
# # => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />
|
455
|
-
def
|
456
|
+
def checkbox_tag(name, *args)
|
456
457
|
if args.length >= 4
|
457
458
|
raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..4)"
|
458
459
|
end
|
@@ -462,6 +463,7 @@ module ActionView
|
|
462
463
|
html_options["checked"] = "checked" if checked
|
463
464
|
tag :input, html_options
|
464
465
|
end
|
466
|
+
alias_method :check_box_tag, :checkbox_tag
|
465
467
|
|
466
468
|
##
|
467
469
|
# :call-seq:
|