actionview 5.2.8.1 → 6.0.6.1

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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +280 -94
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -3
  5. data/lib/action_view/base.rb +108 -11
  6. data/lib/action_view/buffers.rb +15 -0
  7. data/lib/action_view/cache_expiry.rb +53 -0
  8. data/lib/action_view/context.rb +5 -9
  9. data/lib/action_view/digestor.rb +12 -20
  10. data/lib/action_view/flows.rb +0 -1
  11. data/lib/action_view/gem_version.rb +3 -3
  12. data/lib/action_view/helpers/active_model_helper.rb +0 -1
  13. data/lib/action_view/helpers/asset_tag_helper.rb +8 -31
  14. data/lib/action_view/helpers/asset_url_helper.rb +4 -3
  15. data/lib/action_view/helpers/cache_helper.rb +19 -12
  16. data/lib/action_view/helpers/capture_helper.rb +4 -0
  17. data/lib/action_view/helpers/csp_helper.rb +4 -2
  18. data/lib/action_view/helpers/csrf_helper.rb +1 -1
  19. data/lib/action_view/helpers/date_helper.rb +70 -27
  20. data/lib/action_view/helpers/form_helper.rb +240 -8
  21. data/lib/action_view/helpers/form_options_helper.rb +27 -18
  22. data/lib/action_view/helpers/form_tag_helper.rb +17 -15
  23. data/lib/action_view/helpers/javascript_helper.rb +9 -8
  24. data/lib/action_view/helpers/number_helper.rb +8 -2
  25. data/lib/action_view/helpers/output_safety_helper.rb +1 -1
  26. data/lib/action_view/helpers/rendering_helper.rb +6 -4
  27. data/lib/action_view/helpers/sanitize_helper.rb +12 -18
  28. data/lib/action_view/helpers/tag_helper.rb +8 -7
  29. data/lib/action_view/helpers/tags/base.rb +9 -6
  30. data/lib/action_view/helpers/tags/check_box.rb +0 -1
  31. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -1
  32. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -1
  33. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -1
  34. data/lib/action_view/helpers/tags/color_field.rb +1 -2
  35. data/lib/action_view/helpers/tags/date_field.rb +0 -1
  36. data/lib/action_view/helpers/tags/date_select.rb +0 -1
  37. data/lib/action_view/helpers/tags/datetime_field.rb +0 -1
  38. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -1
  39. data/lib/action_view/helpers/tags/label.rb +0 -1
  40. data/lib/action_view/helpers/tags/month_field.rb +0 -1
  41. data/lib/action_view/helpers/tags/radio_button.rb +0 -1
  42. data/lib/action_view/helpers/tags/select.rb +0 -1
  43. data/lib/action_view/helpers/tags/text_field.rb +0 -1
  44. data/lib/action_view/helpers/tags/time_field.rb +0 -1
  45. data/lib/action_view/helpers/tags/translator.rb +1 -6
  46. data/lib/action_view/helpers/tags/week_field.rb +0 -1
  47. data/lib/action_view/helpers/text_helper.rb +3 -4
  48. data/lib/action_view/helpers/translation_helper.rb +19 -17
  49. data/lib/action_view/helpers/url_helper.rb +14 -14
  50. data/lib/action_view/helpers.rb +0 -2
  51. data/lib/action_view/layouts.rb +5 -8
  52. data/lib/action_view/log_subscriber.rb +6 -7
  53. data/lib/action_view/lookup_context.rb +75 -32
  54. data/lib/action_view/path_set.rb +5 -11
  55. data/lib/action_view/railtie.rb +24 -1
  56. data/lib/action_view/record_identifier.rb +2 -3
  57. data/lib/action_view/renderer/abstract_renderer.rb +56 -4
  58. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +63 -17
  59. data/lib/action_view/renderer/partial_renderer.rb +67 -57
  60. data/lib/action_view/renderer/renderer.rb +16 -4
  61. data/lib/action_view/renderer/streaming_template_renderer.rb +5 -7
  62. data/lib/action_view/renderer/template_renderer.rb +25 -20
  63. data/lib/action_view/rendering.rb +51 -32
  64. data/lib/action_view/routing_url_for.rb +12 -11
  65. data/lib/action_view/template/error.rb +30 -15
  66. data/lib/action_view/template/handlers/builder.rb +2 -2
  67. data/lib/action_view/template/handlers/erb/erubi.rb +7 -3
  68. data/lib/action_view/template/handlers/erb.rb +17 -8
  69. data/lib/action_view/template/handlers/html.rb +1 -1
  70. data/lib/action_view/template/handlers/raw.rb +2 -2
  71. data/lib/action_view/template/handlers.rb +27 -1
  72. data/lib/action_view/template/html.rb +14 -5
  73. data/lib/action_view/template/inline.rb +22 -0
  74. data/lib/action_view/template/raw_file.rb +28 -0
  75. data/lib/action_view/template/resolver.rb +134 -135
  76. data/lib/action_view/template/sources/file.rb +17 -0
  77. data/lib/action_view/template/sources.rb +13 -0
  78. data/lib/action_view/template/text.rb +5 -3
  79. data/lib/action_view/template.rb +102 -71
  80. data/lib/action_view/test_case.rb +3 -4
  81. data/lib/action_view/testing/resolvers.rb +33 -21
  82. data/lib/action_view/unbound_template.rb +31 -0
  83. data/lib/action_view/view_paths.rb +25 -2
  84. data/lib/action_view.rb +4 -2
  85. data/lib/assets/compiled/rails-ujs.js +30 -4
  86. metadata +27 -18
  87. 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,13 +683,11 @@ 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
690
-
691
691
  def normalize_distance_of_time_argument_to_time(value)
692
692
  if value.is_a?(Numeric)
693
693
  Time.at(value)
@@ -702,7 +702,7 @@ module ActionView
702
702
  class DateTimeSelector #:nodoc:
703
703
  include ActionView::Helpers::TagHelper
704
704
 
705
- DEFAULT_PREFIX = "date".freeze
705
+ DEFAULT_PREFIX = "date"
706
706
  POSITION = {
707
707
  year: 1, month: 2, day: 3, hour: 4, minute: 5, second: 6
708
708
  }.freeze
@@ -823,14 +823,14 @@ module ActionView
823
823
  1.upto(12) do |month_number|
824
824
  options = { value: month_number }
825
825
  options[:selected] = "selected" if month == month_number
826
- month_options << content_tag("option".freeze, month_name(month_number), options) + "\n"
826
+ month_options << content_tag("option", month_name(month_number), options) + "\n"
827
827
  end
828
828
  build_select(:month, month_options.join)
829
829
  end
830
830
  end
831
831
 
832
832
  def select_year
833
- if !@datetime || @datetime == 0
833
+ if !year || @datetime == 0
834
834
  val = "1"
835
835
  middle_year = Date.today.year
836
836
  else
@@ -851,7 +851,7 @@ module ActionView
851
851
  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
852
  end
853
853
 
854
- build_options_and_select(:year, val, options)
854
+ build_select(:year, build_year_options(val, options))
855
855
  end
856
856
  end
857
857
 
@@ -934,6 +934,21 @@ module ActionView
934
934
  end
935
935
  end
936
936
 
937
+ # Looks up year names by number.
938
+ #
939
+ # year_name(1998) # => 1998
940
+ #
941
+ # If the <tt>:year_format</tt> option is passed:
942
+ #
943
+ # year_name(1998) # => "Heisei 10"
944
+ def year_name(number)
945
+ if year_format_lambda = @options[:year_format]
946
+ year_format_lambda.call(number)
947
+ else
948
+ number
949
+ end
950
+ end
951
+
937
952
  def date_order
938
953
  @date_order ||= @options[:order] || translated_date_order
939
954
  end
@@ -990,7 +1005,35 @@ module ActionView
990
1005
  tag_options[:selected] = "selected" if selected == i
991
1006
  text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value
992
1007
  text = options[:ampm] ? AMPM_TRANSLATION[i] : text
993
- select_options << content_tag("option".freeze, text, tag_options)
1008
+ select_options << content_tag("option", text, tag_options)
1009
+ end
1010
+
1011
+ (select_options.join("\n") + "\n").html_safe
1012
+ end
1013
+
1014
+ # Build select option HTML for year.
1015
+ # If <tt>year_format</tt> option is not passed
1016
+ # build_year_options(1998, start: 1998, end: 2000)
1017
+ # => "<option value="1998" selected="selected">1998</option>
1018
+ # <option value="1999">1999</option>
1019
+ # <option value="2000">2000</option>"
1020
+ #
1021
+ # If <tt>year_format</tt> option is passed
1022
+ # build_year_options(1998, start: 1998, end: 2000, year_format: ->year { "Heisei #{ year - 1988 }" })
1023
+ # => "<option value="1998" selected="selected">Heisei 10</option>
1024
+ # <option value="1999">Heisei 11</option>
1025
+ # <option value="2000">Heisei 12</option>"
1026
+ def build_year_options(selected, options = {})
1027
+ start = options.delete(:start)
1028
+ stop = options.delete(:end)
1029
+ step = options.delete(:step)
1030
+
1031
+ select_options = []
1032
+ start.step(stop, step) do |value|
1033
+ tag_options = { value: value }
1034
+ tag_options[:selected] = "selected" if selected == value
1035
+ text = year_name(value)
1036
+ select_options << content_tag("option", text, tag_options)
994
1037
  end
995
1038
 
996
1039
  (select_options.join("\n") + "\n").html_safe
@@ -1009,12 +1052,12 @@ module ActionView
1009
1052
  select_options[:disabled] = "disabled" if @options[:disabled]
1010
1053
  select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
1011
1054
 
1012
- select_html = "\n".dup
1013
- select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
1055
+ select_html = +"\n"
1056
+ select_html << content_tag("option", "", value: "") + "\n" if @options[:include_blank]
1014
1057
  select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
1015
1058
  select_html << select_options_as_html
1016
1059
 
1017
- (content_tag("select".freeze, select_html.html_safe, select_options) + "\n").html_safe
1060
+ (content_tag("select", select_html.html_safe, select_options) + "\n").html_safe
1018
1061
  end
1019
1062
 
1020
1063
  # Builds the css class value for the select element
@@ -1047,7 +1090,7 @@ module ActionView
1047
1090
  I18n.translate(:"datetime.prompts.#{type}", locale: @options[:locale])
1048
1091
  end
1049
1092
 
1050
- prompt ? content_tag("option".freeze, prompt, value: "") : ""
1093
+ prompt ? content_tag("option", prompt, value: "") : ""
1051
1094
  end
1052
1095
 
1053
1096
  # Builds hidden input tag for date part and value.
@@ -1091,7 +1134,7 @@ module ActionView
1091
1134
  # Given an ordering of datetime components, create the selection HTML
1092
1135
  # and join them with their appropriate separators.
1093
1136
  def build_selects_from_types(order)
1094
- select = "".dup
1137
+ select = +""
1095
1138
  first_visible = order.find { |type| !@options[:"discard_#{type}"] }
1096
1139
  order.reverse_each do |type|
1097
1140
  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.
@@ -752,10 +755,10 @@ module ActionView
752
755
  output = capture(builder, &block)
753
756
  options[:multipart] ||= builder.multipart?
754
757
 
755
- html_options = html_options_for_form_with(url, model, options)
758
+ html_options = html_options_for_form_with(url, model, **options)
756
759
  form_tag_with_body(html_options, output)
757
760
  else
758
- html_options = html_options_for_form_with(url, model, options)
761
+ html_options = html_options_for_form_with(url, model, **options)
759
762
  form_tag_html(html_options)
760
763
  end
761
764
  end
@@ -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