actionview 5.2.8.1 → 6.0.0.beta1

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.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +106 -162
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/action_view/buffers.rb +15 -0
  6. data/lib/action_view/context.rb +5 -4
  7. data/lib/action_view/digestor.rb +7 -6
  8. data/lib/action_view/gem_version.rb +4 -4
  9. data/lib/action_view/helpers/asset_tag_helper.rb +4 -27
  10. data/lib/action_view/helpers/asset_url_helper.rb +4 -3
  11. data/lib/action_view/helpers/cache_helper.rb +18 -10
  12. data/lib/action_view/helpers/capture_helper.rb +4 -0
  13. data/lib/action_view/helpers/csrf_helper.rb +1 -1
  14. data/lib/action_view/helpers/date_helper.rb +69 -25
  15. data/lib/action_view/helpers/form_helper.rb +240 -8
  16. data/lib/action_view/helpers/form_options_helper.rb +23 -15
  17. data/lib/action_view/helpers/form_tag_helper.rb +9 -9
  18. data/lib/action_view/helpers/javascript_helper.rb +10 -11
  19. data/lib/action_view/helpers/number_helper.rb +5 -0
  20. data/lib/action_view/helpers/sanitize_helper.rb +3 -3
  21. data/lib/action_view/helpers/tag_helper.rb +13 -43
  22. data/lib/action_view/helpers/tags/base.rb +8 -4
  23. data/lib/action_view/helpers/tags/color_field.rb +1 -1
  24. data/lib/action_view/helpers/tags/translator.rb +1 -6
  25. data/lib/action_view/helpers/text_helper.rb +3 -3
  26. data/lib/action_view/helpers/translation_helper.rb +11 -18
  27. data/lib/action_view/helpers/url_helper.rb +14 -14
  28. data/lib/action_view/helpers.rb +0 -2
  29. data/lib/action_view/log_subscriber.rb +6 -6
  30. data/lib/action_view/lookup_context.rb +4 -4
  31. data/lib/action_view/railtie.rb +18 -0
  32. data/lib/action_view/record_identifier.rb +2 -2
  33. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +40 -1
  34. data/lib/action_view/renderer/partial_renderer.rb +2 -2
  35. data/lib/action_view/renderer/streaming_template_renderer.rb +1 -1
  36. data/lib/action_view/rendering.rb +5 -4
  37. data/lib/action_view/routing_url_for.rb +12 -11
  38. data/lib/action_view/template/handlers/erb.rb +12 -2
  39. data/lib/action_view/template/resolver.rb +56 -16
  40. data/lib/action_view/template.rb +25 -8
  41. data/lib/action_view/test_case.rb +1 -1
  42. data/lib/action_view/testing/resolvers.rb +1 -1
  43. data/lib/action_view.rb +1 -1
  44. data/lib/assets/compiled/rails-ujs.js +39 -22
  45. metadata +17 -18
  46. data/lib/action_view/helpers/record_tag_helper.rb +0 -23
@@ -205,6 +205,7 @@ module ActionView
205
205
  # * <tt>:end_year</tt> - Set the end year for the year select. Default is <tt>Date.today.year + 5</tt> if
206
206
  # you are creating new record. While editing existing record, <tt>:end_year</tt> defaults to
207
207
  # the current selected year plus 5.
208
+ # * <tt>:year_format</tt> - Set format of years for year select. Lambda should be passed.
208
209
  # * <tt>:discard_day</tt> - Set to true if you don't want to show a day select. This includes the day
209
210
  # as a hidden field instead of showing a select field. Also note that this implicitly sets the day to be the
210
211
  # first of the given month in order to not create invalid dates like 31 February.
@@ -275,6 +276,9 @@ module ActionView
275
276
  # # Generates a date select with custom prompts.
276
277
  # date_select("article", "written_on", prompt: { day: 'Select day', month: 'Select month', year: 'Select year' })
277
278
  #
279
+ # # Generates a date select with custom year format.
280
+ # date_select("article", "written_on", year_format: ->(year) { "Heisei #{year - 1988}" })
281
+ #
278
282
  # The selects are prepared for multi-parameter assignment to an Active Record object.
279
283
  #
280
284
  # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that
@@ -302,15 +306,15 @@ module ActionView
302
306
  # time_select("article", "start_time", include_seconds: true)
303
307
  #
304
308
  # # You can set the <tt>:minute_step</tt> to 15 which will give you: 00, 15, 30, and 45.
305
- # time_select 'game', 'game_time', {minute_step: 15}
309
+ # time_select 'game', 'game_time', { minute_step: 15 }
306
310
  #
307
311
  # # Creates a time select tag with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
308
- # time_select("article", "written_on", prompt: {hour: 'Choose hour', minute: 'Choose minute', second: 'Choose seconds'})
309
- # time_select("article", "written_on", prompt: {hour: true}) # generic prompt for hours
312
+ # time_select("article", "written_on", prompt: { hour: 'Choose hour', minute: 'Choose minute', second: 'Choose seconds' })
313
+ # time_select("article", "written_on", prompt: { hour: true }) # generic prompt for hours
310
314
  # time_select("article", "written_on", prompt: true) # generic prompts for all
311
315
  #
312
316
  # # You can set :ampm option to true which will show the hours as: 12 PM, 01 AM .. 11 PM.
313
- # time_select 'game', 'game_time', {ampm: true}
317
+ # time_select 'game', 'game_time', { ampm: true }
314
318
  #
315
319
  # The selects are prepared for multi-parameter assignment to an Active Record object.
316
320
  #
@@ -346,8 +350,8 @@ module ActionView
346
350
  # datetime_select("article", "written_on", discard_type: true)
347
351
  #
348
352
  # # Generates a datetime select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
349
- # datetime_select("article", "written_on", prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
350
- # datetime_select("article", "written_on", prompt: {hour: true}) # generic prompt for hours
353
+ # datetime_select("article", "written_on", prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' })
354
+ # datetime_select("article", "written_on", prompt: { hour: true }) # generic prompt for hours
351
355
  # datetime_select("article", "written_on", prompt: true) # generic prompts for all
352
356
  #
353
357
  # The selects are prepared for multi-parameter assignment to an Active Record object.
@@ -397,8 +401,8 @@ module ActionView
397
401
  # select_datetime(my_date_time, prefix: 'payday')
398
402
  #
399
403
  # # Generates a datetime select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
400
- # select_datetime(my_date_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
401
- # select_datetime(my_date_time, prompt: {hour: true}) # generic prompt for hours
404
+ # select_datetime(my_date_time, prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' })
405
+ # select_datetime(my_date_time, prompt: { hour: true }) # generic prompt for hours
402
406
  # select_datetime(my_date_time, prompt: true) # generic prompts for all
403
407
  def select_datetime(datetime = Time.current, options = {}, html_options = {})
404
408
  DateTimeSelector.new(datetime, options, html_options).select_datetime
@@ -436,8 +440,8 @@ module ActionView
436
440
  # select_date(my_date, prefix: 'payday')
437
441
  #
438
442
  # # Generates a date select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
439
- # select_date(my_date, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
440
- # select_date(my_date, prompt: {hour: true}) # generic prompt for hours
443
+ # select_date(my_date, prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' })
444
+ # select_date(my_date, prompt: { hour: true }) # generic prompt for hours
441
445
  # select_date(my_date, prompt: true) # generic prompts for all
442
446
  def select_date(date = Date.current, options = {}, html_options = {})
443
447
  DateTimeSelector.new(date, options, html_options).select_date
@@ -476,8 +480,8 @@ module ActionView
476
480
  # select_time(my_time, start_hour: 2, end_hour: 14)
477
481
  #
478
482
  # # Generates a time select with a custom prompt. Use <tt>:prompt</tt> to true for generic prompts.
479
- # select_time(my_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
480
- # select_time(my_time, prompt: {hour: true}) # generic prompt for hours
483
+ # select_time(my_time, prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' })
484
+ # select_time(my_time, prompt: { hour: true }) # generic prompt for hours
481
485
  # select_time(my_time, prompt: true) # generic prompts for all
482
486
  def select_time(datetime = Time.current, options = {}, html_options = {})
483
487
  DateTimeSelector.new(datetime, options, html_options).select_time
@@ -668,8 +672,6 @@ module ActionView
668
672
  # <time datetime="2010-11-04T17:55:45+01:00">November 04, 2010 17:55</time>
669
673
  # time_tag Date.yesterday, 'Yesterday' # =>
670
674
  # <time datetime="2010-11-03">Yesterday</time>
671
- # time_tag Date.today, pubdate: true # =>
672
- # <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time>
673
675
  # time_tag Date.today, datetime: Date.today.strftime('%G-W%V') # =>
674
676
  # <time datetime="2010-W44">November 04, 2010</time>
675
677
  #
@@ -681,9 +683,8 @@ module ActionView
681
683
  options = args.extract_options!
682
684
  format = options.delete(:format) || :long
683
685
  content = args.first || I18n.l(date_or_time, format: format)
684
- datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.iso8601
685
686
 
686
- content_tag("time".freeze, content, options.reverse_merge(datetime: datetime), &block)
687
+ content_tag("time", content, options.reverse_merge(datetime: date_or_time.iso8601), &block)
687
688
  end
688
689
 
689
690
  private
@@ -702,7 +703,7 @@ module ActionView
702
703
  class DateTimeSelector #:nodoc:
703
704
  include ActionView::Helpers::TagHelper
704
705
 
705
- DEFAULT_PREFIX = "date".freeze
706
+ DEFAULT_PREFIX = "date"
706
707
  POSITION = {
707
708
  year: 1, month: 2, day: 3, hour: 4, minute: 5, second: 6
708
709
  }.freeze
@@ -823,7 +824,7 @@ module ActionView
823
824
  1.upto(12) do |month_number|
824
825
  options = { value: month_number }
825
826
  options[:selected] = "selected" if month == month_number
826
- month_options << content_tag("option".freeze, month_name(month_number), options) + "\n"
827
+ month_options << content_tag("option", month_name(month_number), options) + "\n"
827
828
  end
828
829
  build_select(:month, month_options.join)
829
830
  end
@@ -851,7 +852,7 @@ module ActionView
851
852
  raise ArgumentError, "There are too many years options to be built. Are you sure you haven't mistyped something? You can provide the :max_years_allowed parameter."
852
853
  end
853
854
 
854
- build_options_and_select(:year, val, options)
855
+ build_select(:year, build_year_options(val, options))
855
856
  end
856
857
  end
857
858
 
@@ -934,6 +935,21 @@ module ActionView
934
935
  end
935
936
  end
936
937
 
938
+ # Looks up year names by number.
939
+ #
940
+ # year_name(1998) # => 1998
941
+ #
942
+ # If the <tt>:year_format</tt> option is passed:
943
+ #
944
+ # year_name(1998) # => "Heisei 10"
945
+ def year_name(number)
946
+ if year_format_lambda = @options[:year_format]
947
+ year_format_lambda.call(number)
948
+ else
949
+ number
950
+ end
951
+ end
952
+
937
953
  def date_order
938
954
  @date_order ||= @options[:order] || translated_date_order
939
955
  end
@@ -990,7 +1006,35 @@ module ActionView
990
1006
  tag_options[:selected] = "selected" if selected == i
991
1007
  text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value
992
1008
  text = options[:ampm] ? AMPM_TRANSLATION[i] : text
993
- select_options << content_tag("option".freeze, text, tag_options)
1009
+ select_options << content_tag("option", text, tag_options)
1010
+ end
1011
+
1012
+ (select_options.join("\n") + "\n").html_safe
1013
+ end
1014
+
1015
+ # Build select option HTML for year.
1016
+ # If <tt>year_format</tt> option is not passed
1017
+ # build_year_options(1998, start: 1998, end: 2000)
1018
+ # => "<option value="1998" selected="selected">1998</option>
1019
+ # <option value="1999">1999</option>
1020
+ # <option value="2000">2000</option>"
1021
+ #
1022
+ # If <tt>year_format</tt> option is passed
1023
+ # build_year_options(1998, start: 1998, end: 2000, year_format: ->year { "Heisei #{ year - 1988 }" })
1024
+ # => "<option value="1998" selected="selected">Heisei 10</option>
1025
+ # <option value="1999">Heisei 11</option>
1026
+ # <option value="2000">Heisei 12</option>"
1027
+ def build_year_options(selected, options = {})
1028
+ start = options.delete(:start)
1029
+ stop = options.delete(:end)
1030
+ step = options.delete(:step)
1031
+
1032
+ select_options = []
1033
+ start.step(stop, step) do |value|
1034
+ tag_options = { value: value }
1035
+ tag_options[:selected] = "selected" if selected == value
1036
+ text = year_name(value)
1037
+ select_options << content_tag("option", text, tag_options)
994
1038
  end
995
1039
 
996
1040
  (select_options.join("\n") + "\n").html_safe
@@ -1009,12 +1053,12 @@ module ActionView
1009
1053
  select_options[:disabled] = "disabled" if @options[:disabled]
1010
1054
  select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
1011
1055
 
1012
- select_html = "\n".dup
1013
- select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
1056
+ select_html = +"\n"
1057
+ select_html << content_tag("option", "", value: "") + "\n" if @options[:include_blank]
1014
1058
  select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
1015
1059
  select_html << select_options_as_html
1016
1060
 
1017
- (content_tag("select".freeze, select_html.html_safe, select_options) + "\n").html_safe
1061
+ (content_tag("select", select_html.html_safe, select_options) + "\n").html_safe
1018
1062
  end
1019
1063
 
1020
1064
  # Builds the css class value for the select element
@@ -1047,7 +1091,7 @@ module ActionView
1047
1091
  I18n.translate(:"datetime.prompts.#{type}", locale: @options[:locale])
1048
1092
  end
1049
1093
 
1050
- prompt ? content_tag("option".freeze, prompt, value: "") : ""
1094
+ prompt ? content_tag("option", prompt, value: "") : ""
1051
1095
  end
1052
1096
 
1053
1097
  # Builds hidden input tag for date part and value.
@@ -1091,7 +1135,7 @@ module ActionView
1091
1135
  # Given an ordering of datetime components, create the selection HTML
1092
1136
  # and join them with their appropriate separators.
1093
1137
  def build_selects_from_types(order)
1094
- select = "".dup
1138
+ select = +""
1095
1139
  first_visible = order.find { |type| !@options[:"discard_#{type}"] }
1096
1140
  order.reverse_each do |type|
1097
1141
  separator = separator(type) unless type == first_visible # don't add before first visible field
@@ -590,6 +590,9 @@ module ActionView
590
590
  # Skipped if a <tt>:url</tt> is passed.
591
591
  # * <tt>:scope</tt> - The scope to prefix input field names with and
592
592
  # thereby how the submitted parameters are grouped in controllers.
593
+ # * <tt>:namespace</tt> - A namespace for your form to ensure uniqueness of
594
+ # id attributes on form elements. The namespace attribute will be prefixed
595
+ # with underscore on the generated HTML id.
593
596
  # * <tt>:model</tt> - A model object to infer the <tt>:url</tt> and
594
597
  # <tt>:scope</tt> by, plus fill out input field values.
595
598
  # So if a +title+ attribute is set to "Ahoy!" then a +title+ input
@@ -610,8 +613,8 @@ module ActionView
610
613
  # unnecessary unless you support browsers without JavaScript.
611
614
  # * <tt>:local</tt> - By default form submits are remote and unobtrusive XHRs.
612
615
  # Disable remote submits with <tt>local: true</tt>.
613
- # * <tt>:skip_enforcing_utf8</tt> - By default a hidden field named +utf8+
614
- # is output to enforce UTF-8 submits. Set to true to skip the field.
616
+ # * <tt>:skip_enforcing_utf8</tt> - If set to true, a hidden input with name
617
+ # utf8 is not output.
615
618
  # * <tt>:builder</tt> - Override the object used to build the form.
616
619
  # * <tt>:id</tt> - Optional HTML id attribute.
617
620
  # * <tt>:class</tt> - Optional HTML class attribute.
@@ -736,7 +739,7 @@ module ActionView
736
739
  # def labelled_form_with(**options, &block)
737
740
  # form_with(**options.merge(builder: LabellingFormBuilder), &block)
738
741
  # end
739
- def form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
742
+ def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
740
743
  options[:allow_method_names_outside_object] = true
741
744
  options[:skip_default_ids] = !form_with_generates_ids
742
745
 
@@ -749,7 +752,7 @@ module ActionView
749
752
 
750
753
  if block_given?
751
754
  builder = instantiate_builder(scope, model, options)
752
- output = capture(builder, &block)
755
+ output = capture(builder, &Proc.new)
753
756
  options[:multipart] ||= builder.multipart?
754
757
 
755
758
  html_options = html_options_for_form_with(url, model, options)
@@ -1127,6 +1130,9 @@ module ActionView
1127
1130
  # text_field(:post, :title, class: "create_input")
1128
1131
  # # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" class="create_input" />
1129
1132
  #
1133
+ # text_field(:post, :title, maxlength: 30, class: "title_input")
1134
+ # # => <input type="text" id="post_title" name="post[title]" maxlength="30" size="30" value="#{@post.title}" class="title_input" />
1135
+ #
1130
1136
  # text_field(:session, :user, onchange: "if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }")
1131
1137
  # # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange="if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }"/>
1132
1138
  #
@@ -1519,10 +1525,10 @@ module ActionView
1519
1525
 
1520
1526
  private
1521
1527
  def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: !form_with_generates_remote_forms,
1522
- skip_enforcing_utf8: false, **options)
1528
+ skip_enforcing_utf8: nil, **options)
1523
1529
  html_options = options.slice(:id, :class, :multipart, :method, :data).merge(html)
1524
1530
  html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted?
1525
- html_options[:enforce_utf8] = !skip_enforcing_utf8
1531
+ html_options[:enforce_utf8] = !skip_enforcing_utf8 unless skip_enforcing_utf8.nil?
1526
1532
 
1527
1533
  html_options[:enctype] = "multipart/form-data" if html_options.delete(:multipart)
1528
1534
 
@@ -1674,6 +1680,227 @@ module ActionView
1674
1680
  @index = options[:index] || options[:child_index]
1675
1681
  end
1676
1682
 
1683
+ ##
1684
+ # :method: text_field
1685
+ #
1686
+ # :call-seq: text_field(method, options = {})
1687
+ #
1688
+ # Wraps ActionView::Helpers::FormHelper#text_field for form builders:
1689
+ #
1690
+ # <%= form_with model: @user do |f| %>
1691
+ # <%= f.text_field :name %>
1692
+ # <% end %>
1693
+ #
1694
+ # Please refer to the documentation of the base helper for details.
1695
+
1696
+ ##
1697
+ # :method: password_field
1698
+ #
1699
+ # :call-seq: password_field(method, options = {})
1700
+ #
1701
+ # Wraps ActionView::Helpers::FormHelper#password_field for form builders:
1702
+ #
1703
+ # <%= form_with model: @user do |f| %>
1704
+ # <%= f.password_field :password %>
1705
+ # <% end %>
1706
+ #
1707
+ # Please refer to the documentation of the base helper for details.
1708
+
1709
+ ##
1710
+ # :method: text_area
1711
+ #
1712
+ # :call-seq: text_area(method, options = {})
1713
+ #
1714
+ # Wraps ActionView::Helpers::FormHelper#text_area for form builders:
1715
+ #
1716
+ # <%= form_with model: @user do |f| %>
1717
+ # <%= f.text_area :detail %>
1718
+ # <% end %>
1719
+ #
1720
+ # Please refer to the documentation of the base helper for details.
1721
+
1722
+ ##
1723
+ # :method: color_field
1724
+ #
1725
+ # :call-seq: color_field(method, options = {})
1726
+ #
1727
+ # Wraps ActionView::Helpers::FormHelper#color_field for form builders:
1728
+ #
1729
+ # <%= form_with model: @user do |f| %>
1730
+ # <%= f.color_field :favorite_color %>
1731
+ # <% end %>
1732
+ #
1733
+ # Please refer to the documentation of the base helper for details.
1734
+
1735
+ ##
1736
+ # :method: search_field
1737
+ #
1738
+ # :call-seq: search_field(method, options = {})
1739
+ #
1740
+ # Wraps ActionView::Helpers::FormHelper#search_field for form builders:
1741
+ #
1742
+ # <%= form_with model: @user do |f| %>
1743
+ # <%= f.search_field :name %>
1744
+ # <% end %>
1745
+ #
1746
+ # Please refer to the documentation of the base helper for details.
1747
+
1748
+ ##
1749
+ # :method: telephone_field
1750
+ #
1751
+ # :call-seq: telephone_field(method, options = {})
1752
+ #
1753
+ # Wraps ActionView::Helpers::FormHelper#telephone_field for form builders:
1754
+ #
1755
+ # <%= form_with model: @user do |f| %>
1756
+ # <%= f.telephone_field :phone %>
1757
+ # <% end %>
1758
+ #
1759
+ # Please refer to the documentation of the base helper for details.
1760
+
1761
+ ##
1762
+ # :method: phone_field
1763
+ #
1764
+ # :call-seq: phone_field(method, options = {})
1765
+ #
1766
+ # Wraps ActionView::Helpers::FormHelper#phone_field for form builders:
1767
+ #
1768
+ # <%= form_with model: @user do |f| %>
1769
+ # <%= f.phone_field :phone %>
1770
+ # <% end %>
1771
+ #
1772
+ # Please refer to the documentation of the base helper for details.
1773
+
1774
+ ##
1775
+ # :method: date_field
1776
+ #
1777
+ # :call-seq: date_field(method, options = {})
1778
+ #
1779
+ # Wraps ActionView::Helpers::FormHelper#date_field for form builders:
1780
+ #
1781
+ # <%= form_with model: @user do |f| %>
1782
+ # <%= f.date_field :born_on %>
1783
+ # <% end %>
1784
+ #
1785
+ # Please refer to the documentation of the base helper for details.
1786
+
1787
+ ##
1788
+ # :method: time_field
1789
+ #
1790
+ # :call-seq: time_field(method, options = {})
1791
+ #
1792
+ # Wraps ActionView::Helpers::FormHelper#time_field for form builders:
1793
+ #
1794
+ # <%= form_with model: @user do |f| %>
1795
+ # <%= f.time_field :borned_at %>
1796
+ # <% end %>
1797
+ #
1798
+ # Please refer to the documentation of the base helper for details.
1799
+
1800
+ ##
1801
+ # :method: datetime_field
1802
+ #
1803
+ # :call-seq: datetime_field(method, options = {})
1804
+ #
1805
+ # Wraps ActionView::Helpers::FormHelper#datetime_field for form builders:
1806
+ #
1807
+ # <%= form_with model: @user do |f| %>
1808
+ # <%= f.datetime_field :graduation_day %>
1809
+ # <% end %>
1810
+ #
1811
+ # Please refer to the documentation of the base helper for details.
1812
+
1813
+ ##
1814
+ # :method: datetime_local_field
1815
+ #
1816
+ # :call-seq: datetime_local_field(method, options = {})
1817
+ #
1818
+ # Wraps ActionView::Helpers::FormHelper#datetime_local_field for form builders:
1819
+ #
1820
+ # <%= form_with model: @user do |f| %>
1821
+ # <%= f.datetime_local_field :graduation_day %>
1822
+ # <% end %>
1823
+ #
1824
+ # Please refer to the documentation of the base helper for details.
1825
+
1826
+ ##
1827
+ # :method: month_field
1828
+ #
1829
+ # :call-seq: month_field(method, options = {})
1830
+ #
1831
+ # Wraps ActionView::Helpers::FormHelper#month_field for form builders:
1832
+ #
1833
+ # <%= form_with model: @user do |f| %>
1834
+ # <%= f.month_field :birthday_month %>
1835
+ # <% end %>
1836
+ #
1837
+ # Please refer to the documentation of the base helper for details.
1838
+
1839
+ ##
1840
+ # :method: week_field
1841
+ #
1842
+ # :call-seq: week_field(method, options = {})
1843
+ #
1844
+ # Wraps ActionView::Helpers::FormHelper#week_field for form builders:
1845
+ #
1846
+ # <%= form_with model: @user do |f| %>
1847
+ # <%= f.week_field :birthday_week %>
1848
+ # <% end %>
1849
+ #
1850
+ # Please refer to the documentation of the base helper for details.
1851
+
1852
+ ##
1853
+ # :method: url_field
1854
+ #
1855
+ # :call-seq: url_field(method, options = {})
1856
+ #
1857
+ # Wraps ActionView::Helpers::FormHelper#url_field for form builders:
1858
+ #
1859
+ # <%= form_with model: @user do |f| %>
1860
+ # <%= f.url_field :homepage %>
1861
+ # <% end %>
1862
+ #
1863
+ # Please refer to the documentation of the base helper for details.
1864
+
1865
+ ##
1866
+ # :method: email_field
1867
+ #
1868
+ # :call-seq: email_field(method, options = {})
1869
+ #
1870
+ # Wraps ActionView::Helpers::FormHelper#email_field for form builders:
1871
+ #
1872
+ # <%= form_with model: @user do |f| %>
1873
+ # <%= f.email_field :address %>
1874
+ # <% end %>
1875
+ #
1876
+ # Please refer to the documentation of the base helper for details.
1877
+
1878
+ ##
1879
+ # :method: number_field
1880
+ #
1881
+ # :call-seq: number_field(method, options = {})
1882
+ #
1883
+ # Wraps ActionView::Helpers::FormHelper#number_field for form builders:
1884
+ #
1885
+ # <%= form_with model: @user do |f| %>
1886
+ # <%= f.number_field :age %>
1887
+ # <% end %>
1888
+ #
1889
+ # Please refer to the documentation of the base helper for details.
1890
+
1891
+ ##
1892
+ # :method: range_field
1893
+ #
1894
+ # :call-seq: range_field(method, options = {})
1895
+ #
1896
+ # Wraps ActionView::Helpers::FormHelper#range_field for form builders:
1897
+ #
1898
+ # <%= form_with model: @user do |f| %>
1899
+ # <%= f.range_field :age %>
1900
+ # <% end %>
1901
+ #
1902
+ # Please refer to the documentation of the base helper for details.
1903
+
1677
1904
  (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
1678
1905
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
1679
1906
  def #{selector}(method, options = {}) # def text_field(method, options = {})
@@ -2247,7 +2474,7 @@ module ActionView
2247
2474
  @template.button_tag(value, options, &block)
2248
2475
  end
2249
2476
 
2250
- def emitted_hidden_id?
2477
+ def emitted_hidden_id? # :nodoc:
2251
2478
  @emitted_hidden_id ||= nil
2252
2479
  end
2253
2480
 
@@ -2267,7 +2494,12 @@ module ActionView
2267
2494
  end
2268
2495
 
2269
2496
  defaults = []
2270
- defaults << :"helpers.submit.#{object_name}.#{key}"
2497
+ # Object is a model and it is not overwritten by as and scope option.
2498
+ if object.respond_to?(:model_name) && object_name.to_s == model.downcase
2499
+ defaults << :"helpers.submit.#{object.model_name.i18n_key}.#{key}"
2500
+ else
2501
+ defaults << :"helpers.submit.#{object_name}.#{key}"
2502
+ end
2271
2503
  defaults << :"helpers.submit.#{key}"
2272
2504
  defaults << "#{key.to_s.humanize} #{model}"
2273
2505
 
@@ -16,7 +16,7 @@ module ActionView
16
16
  #
17
17
  # * <tt>:include_blank</tt> - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
18
18
  #
19
- # select("post", "category", Post::CATEGORIES, {include_blank: true})
19
+ # select("post", "category", Post::CATEGORIES, { include_blank: true })
20
20
  #
21
21
  # could become:
22
22
  #
@@ -30,7 +30,7 @@ module ActionView
30
30
  #
31
31
  # Example with <tt>@post.person_id => 2</tt>:
32
32
  #
33
- # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: 'None'})
33
+ # select("post", "person_id", Person.all.collect { |p| [ p.name, p.id ] }, { include_blank: 'None' })
34
34
  #
35
35
  # could become:
36
36
  #
@@ -43,7 +43,7 @@ module ActionView
43
43
  #
44
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
45
  #
46
- # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {prompt: 'Select Person'})
46
+ # select("post", "person_id", Person.all.collect { |p| [ p.name, p.id ] }, { prompt: 'Select Person' })
47
47
  #
48
48
  # could become:
49
49
  #
@@ -69,7 +69,7 @@ module ActionView
69
69
  #
70
70
  # * <tt>:disabled</tt> - can be a single value or an array of values that will be disabled options in the final output.
71
71
  #
72
- # select("post", "category", Post::CATEGORIES, {disabled: 'restricted'})
72
+ # select("post", "category", Post::CATEGORIES, { disabled: 'restricted' })
73
73
  #
74
74
  # could become:
75
75
  #
@@ -82,7 +82,7 @@ module ActionView
82
82
  #
83
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.
84
84
  #
85
- # collection_select(:post, :category_id, Category.all, :id, :name, {disabled: -> (category) { category.archived? }})
85
+ # collection_select(:post, :category_id, Category.all, :id, :name, { disabled: -> (category) { category.archived? } })
86
86
  #
87
87
  # If the categories "2008 stuff" and "Christmas" return true when the method <tt>archived?</tt> is called, this would return:
88
88
  # <select name="post[category_id]" id="post_category_id">
@@ -107,7 +107,7 @@ module ActionView
107
107
  #
108
108
  # For example:
109
109
  #
110
- # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { include_blank: true })
110
+ # select("post", "person_id", Person.all.collect { |p| [ p.name, p.id ] }, { include_blank: true })
111
111
  #
112
112
  # would become:
113
113
  #
@@ -323,12 +323,12 @@ module ActionView
323
323
  #
324
324
  # You can optionally provide HTML attributes as the last element of the array.
325
325
  #
326
- # options_for_select([ "Denmark", ["USA", {class: 'bold'}], "Sweden" ], ["USA", "Sweden"])
326
+ # options_for_select([ "Denmark", ["USA", { class: 'bold' }], "Sweden" ], ["USA", "Sweden"])
327
327
  # # => <option value="Denmark">Denmark</option>
328
328
  # # => <option value="USA" class="bold" selected="selected">USA</option>
329
329
  # # => <option value="Sweden" selected="selected">Sweden</option>
330
330
  #
331
- # options_for_select([["Dollar", "$", {class: "bold"}], ["Kroner", "DKK", {onclick: "alert('HI');"}]])
331
+ # options_for_select([["Dollar", "$", { class: "bold" }], ["Kroner", "DKK", { onclick: "alert('HI');" }]])
332
332
  # # => <option value="$" class="bold">Dollar</option>
333
333
  # # => <option value="DKK" onclick="alert('HI');">Kroner</option>
334
334
  #
@@ -463,7 +463,7 @@ module ActionView
463
463
  option_tags = options_from_collection_for_select(
464
464
  value_for_collection(group, group_method), option_key_method, option_value_method, selected_key)
465
465
 
466
- content_tag("optgroup".freeze, option_tags, label: value_for_collection(group, group_label_method))
466
+ content_tag("optgroup", option_tags, label: value_for_collection(group, group_label_method))
467
467
  end.join.html_safe
468
468
  end
469
469
 
@@ -535,7 +535,7 @@ module ActionView
535
535
  body = "".html_safe
536
536
 
537
537
  if prompt
538
- body.safe_concat content_tag("option".freeze, prompt_text(prompt), value: "")
538
+ body.safe_concat content_tag("option", prompt_text(prompt), value: "")
539
539
  end
540
540
 
541
541
  grouped_options.each do |container|
@@ -548,7 +548,7 @@ module ActionView
548
548
  end
549
549
 
550
550
  html_attributes = { label: label }.merge!(html_attributes)
551
- body.safe_concat content_tag("optgroup".freeze, options_for_select(container, selected_key), html_attributes)
551
+ body.safe_concat content_tag("optgroup", options_for_select(container, selected_key), html_attributes)
552
552
  end
553
553
 
554
554
  body
@@ -584,7 +584,7 @@ module ActionView
584
584
  end
585
585
 
586
586
  zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
587
- zone_options.safe_concat content_tag("option".freeze, "-------------", value: "", disabled: true)
587
+ zone_options.safe_concat content_tag("option", "-------------", value: "", disabled: true)
588
588
  zone_options.safe_concat "\n"
589
589
 
590
590
  zones = zones - priority_zones
@@ -654,7 +654,7 @@ module ActionView
654
654
  #
655
655
  # ==== Gotcha
656
656
  #
657
- # The HTML specification says when nothing is select on a collection of radio buttons
657
+ # The HTML specification says when nothing is selected on a collection of radio buttons
658
658
  # web browsers do not send any value to server.
659
659
  # Unfortunately this introduces a gotcha:
660
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,
@@ -794,7 +794,7 @@ module ActionView
794
794
  def extract_values_from_collection(collection, value_method, selected)
795
795
  if selected.is_a?(Proc)
796
796
  collection.map do |element|
797
- element.send(value_method) if selected.call(element)
797
+ public_or_deprecated_send(element, value_method) if selected.call(element)
798
798
  end.compact
799
799
  else
800
800
  selected
@@ -802,7 +802,15 @@ module ActionView
802
802
  end
803
803
 
804
804
  def value_for_collection(item, value)
805
- value.respond_to?(:call) ? value.call(item) : item.send(value)
805
+ value.respond_to?(:call) ? value.call(item) : public_or_deprecated_send(item, value)
806
+ end
807
+
808
+ def public_or_deprecated_send(item, value)
809
+ item.public_send(value)
810
+ rescue NoMethodError
811
+ raise unless item.respond_to?(value, true) && !item.respond_to?(value)
812
+ ActiveSupport::Deprecation.warn "Using private methods from view helpers is deprecated (calling private #{item.class}##{value})"
813
+ item.send(value)
806
814
  end
807
815
 
808
816
  def prompt_text(prompt)