actionview 7.1.1 → 7.2.3.1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +108 -311
  3. data/README.rdoc +1 -1
  4. data/app/assets/javascripts/rails-ujs.esm.js +0 -7
  5. data/lib/action_view/base.rb +25 -11
  6. data/lib/action_view/cache_expiry.rb +9 -3
  7. data/lib/action_view/dependency_tracker/{ripper_tracker.rb → ruby_tracker.rb} +4 -3
  8. data/lib/action_view/dependency_tracker.rb +1 -1
  9. data/lib/action_view/digestor.rb +6 -2
  10. data/lib/action_view/gem_version.rb +3 -3
  11. data/lib/action_view/helpers/asset_tag_helper.rb +26 -14
  12. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  13. data/lib/action_view/helpers/cache_helper.rb +6 -6
  14. data/lib/action_view/helpers/capture_helper.rb +7 -1
  15. data/lib/action_view/helpers/csrf_helper.rb +1 -1
  16. data/lib/action_view/helpers/date_helper.rb +8 -1
  17. data/lib/action_view/helpers/form_helper.rb +230 -221
  18. data/lib/action_view/helpers/form_options_helper.rb +6 -3
  19. data/lib/action_view/helpers/form_tag_helper.rb +86 -53
  20. data/lib/action_view/helpers/number_helper.rb +35 -329
  21. data/lib/action_view/helpers/output_safety_helper.rb +5 -6
  22. data/lib/action_view/helpers/sanitize_helper.rb +25 -14
  23. data/lib/action_view/helpers/tag_helper.rb +213 -20
  24. data/lib/action_view/helpers/tags/collection_helpers.rb +2 -1
  25. data/lib/action_view/helpers/text_helper.rb +135 -72
  26. data/lib/action_view/helpers/url_helper.rb +8 -80
  27. data/lib/action_view/layouts.rb +10 -12
  28. data/lib/action_view/log_subscriber.rb +8 -4
  29. data/lib/action_view/railtie.rb +0 -1
  30. data/lib/action_view/render_parser/prism_render_parser.rb +127 -0
  31. data/lib/action_view/{ripper_ast_parser.rb → render_parser/ripper_render_parser.rb} +152 -9
  32. data/lib/action_view/render_parser.rb +21 -169
  33. data/lib/action_view/renderer/abstract_renderer.rb +1 -1
  34. data/lib/action_view/renderer/collection_renderer.rb +1 -1
  35. data/lib/action_view/renderer/partial_renderer.rb +2 -2
  36. data/lib/action_view/renderer/renderer.rb +32 -38
  37. data/lib/action_view/renderer/template_renderer.rb +3 -3
  38. data/lib/action_view/rendering.rb +4 -4
  39. data/lib/action_view/template/error.rb +11 -0
  40. data/lib/action_view/template/handlers/erb.rb +45 -37
  41. data/lib/action_view/template/renderable.rb +7 -1
  42. data/lib/action_view/template/resolver.rb +0 -2
  43. data/lib/action_view/template.rb +68 -19
  44. data/lib/action_view/test_case.rb +33 -34
  45. data/lib/action_view/unbound_template.rb +4 -4
  46. data/lib/action_view.rb +2 -1
  47. metadata +30 -19
  48. data/lib/assets/compiled/rails-ujs.js +0 -777
@@ -7,6 +7,7 @@ require "action_view/helpers/form_tag_helper"
7
7
  require "action_view/helpers/active_model_helper"
8
8
  require "action_view/model_naming"
9
9
  require "action_view/record_identifier"
10
+ require "active_support/code_generator"
10
11
  require "active_support/core_ext/module/attribute_accessors"
11
12
  require "active_support/core_ext/hash/slice"
12
13
  require "active_support/core_ext/string/output_safety"
@@ -29,8 +30,8 @@ module ActionView
29
30
  # when the form is initially displayed, input fields corresponding to attributes
30
31
  # of the resource should show the current values of those attributes.
31
32
  #
32
- # In \Rails, this is usually achieved by creating the form using +form_for+ and
33
- # a number of related helper methods. +form_for+ generates an appropriate <tt>form</tt>
33
+ # In \Rails, this is usually achieved by creating the form using #form_for and
34
+ # a number of related helper methods. #form_for generates an appropriate <tt>form</tt>
34
35
  # tag and yields a form builder object that knows the model the form is about.
35
36
  # Input fields are created by calling methods defined on the form builder, which
36
37
  # means they are able to generate the appropriate names and default values
@@ -40,7 +41,7 @@ module ActionView
40
41
  #
41
42
  # For example, to create a new person you typically set up a new instance of
42
43
  # +Person+ in the <tt>PeopleController#new</tt> action, <tt>@person</tt>, and
43
- # in the view template pass that object to +form_for+:
44
+ # in the view template pass that object to #form_for:
44
45
  #
45
46
  # <%= form_for @person do |f| %>
46
47
  # <%= f.label :first_name %>:
@@ -207,23 +208,23 @@ module ActionView
207
208
  # are designed to work with an object as base, like
208
209
  # FormOptionsHelper#collection_select and DateHelper#datetime_select.
209
210
  #
210
- # === #form_for with a model object
211
+ # === +form_for+ with a model object
211
212
  #
212
213
  # In the examples above, the object to be created or edited was
213
214
  # represented by a symbol passed to +form_for+, and we noted that
214
215
  # a string can also be used equivalently. It is also possible, however,
215
- # to pass a model object itself to +form_for+. For example, if <tt>@post</tt>
216
+ # to pass a model object itself to +form_for+. For example, if <tt>@article</tt>
216
217
  # is an existing record you wish to edit, you can create the form using
217
218
  #
218
- # <%= form_for @post do |f| %>
219
+ # <%= form_for @article do |f| %>
219
220
  # ...
220
221
  # <% end %>
221
222
  #
222
223
  # This behaves in almost the same way as outlined previously, with a
223
224
  # couple of small exceptions. First, the prefix used to name the input
224
225
  # elements within the form (hence the key that denotes them in the +params+
225
- # hash) is actually derived from the object's _class_, e.g. <tt>params[:post]</tt>
226
- # if the object's class is +Post+. However, this can be overwritten using
226
+ # hash) is actually derived from the object's _class_, e.g. <tt>params[:article]</tt>
227
+ # if the object's class is +Article+. However, this can be overwritten using
227
228
  # the <tt>:as</tt> option, e.g. -
228
229
  #
229
230
  # <%= form_for(@person, as: :client) do |f| %>
@@ -235,15 +236,15 @@ module ActionView
235
236
  # Secondly, the field values shown when the form is initially displayed
236
237
  # are taken from the attributes of the object passed to +form_for+,
237
238
  # regardless of whether the object is an instance
238
- # variable. So, for example, if we had a _local_ variable +post+
239
+ # variable. So, for example, if we had a _local_ variable +article+
239
240
  # representing an existing record,
240
241
  #
241
- # <%= form_for post do |f| %>
242
+ # <%= form_for article do |f| %>
242
243
  # ...
243
244
  # <% end %>
244
245
  #
245
246
  # would produce a form with fields whose initial state reflect the current
246
- # values of the attributes of +post+.
247
+ # values of the attributes of +article+.
247
248
  #
248
249
  # === Resource-oriented style
249
250
  #
@@ -255,49 +256,49 @@ module ActionView
255
256
  # in <tt>config/routes.rb</tt>. In this case \Rails will simply infer the
256
257
  # appropriate URL from the record itself. For example,
257
258
  #
258
- # <%= form_for @post do |f| %>
259
+ # <%= form_for @article do |f| %>
259
260
  # ...
260
261
  # <% end %>
261
262
  #
262
263
  # is then equivalent to something like:
263
264
  #
264
- # <%= form_for @post, as: :post, url: post_path(@post), method: :patch, html: { class: "edit_post", id: "edit_post_45" } do |f| %>
265
+ # <%= form_for @article, as: :article, url: article_path(@article), method: :patch, html: { class: "edit_article", id: "edit_article_45" } do |f| %>
265
266
  # ...
266
267
  # <% end %>
267
268
  #
268
269
  # And for a new record
269
270
  #
270
- # <%= form_for(Post.new) do |f| %>
271
+ # <%= form_for(Article.new) do |f| %>
271
272
  # ...
272
273
  # <% end %>
273
274
  #
274
275
  # is equivalent to something like:
275
276
  #
276
- # <%= form_for @post, as: :post, url: posts_path, html: { class: "new_post", id: "new_post" } do |f| %>
277
+ # <%= form_for @article, as: :article, url: articles_path, html: { class: "new_article", id: "new_article" } do |f| %>
277
278
  # ...
278
279
  # <% end %>
279
280
  #
280
281
  # However you can still overwrite individual conventions, such as:
281
282
  #
282
- # <%= form_for(@post, url: super_posts_path) do |f| %>
283
+ # <%= form_for(@article, url: super_articles_path) do |f| %>
283
284
  # ...
284
285
  # <% end %>
285
286
  #
286
287
  # You can omit the <tt>action</tt> attribute by passing <tt>url: false</tt>:
287
288
  #
288
- # <%= form_for(@post, url: false) do |f| %>
289
+ # <%= form_for(@article, url: false) do |f| %>
289
290
  # ...
290
291
  # <% end %>
291
292
  #
292
293
  # You can also set the answer format, like this:
293
294
  #
294
- # <%= form_for(@post, format: :json) do |f| %>
295
+ # <%= form_for(@article, format: :json) do |f| %>
295
296
  # ...
296
297
  # <% end %>
297
298
  #
298
- # For namespaced routes, like +admin_post_url+:
299
+ # For namespaced routes, like +admin_article_url+:
299
300
  #
300
- # <%= form_for([:admin, @post]) do |f| %>
301
+ # <%= form_for([:admin, @article]) do |f| %>
301
302
  # ...
302
303
  # <% end %>
303
304
  #
@@ -333,7 +334,7 @@ module ActionView
333
334
  #
334
335
  # Example:
335
336
  #
336
- # <%= form_for(@post, remote: true) do |f| %>
337
+ # <%= form_for(@article, remote: true) do |f| %>
337
338
  # ...
338
339
  # <% end %>
339
340
  #
@@ -349,7 +350,7 @@ module ActionView
349
350
  # You can set data attributes directly by passing in a data hash, but all other HTML options must be wrapped in
350
351
  # the HTML key. Example:
351
352
  #
352
- # <%= form_for(@post, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %>
353
+ # <%= form_for(@article, data: { behavior: "autosave" }, html: { name: "go" }) do |f| %>
353
354
  # ...
354
355
  # <% end %>
355
356
  #
@@ -362,17 +363,17 @@ module ActionView
362
363
  #
363
364
  # === Removing hidden model id's
364
365
  #
365
- # The form_for method automatically includes the model id as a hidden field in the form.
366
+ # The +form_for+ method automatically includes the model id as a hidden field in the form.
366
367
  # This is used to maintain the correlation between the form data and its associated model.
367
368
  # Some ORM systems do not use IDs on nested models so in this case you want to be able
368
369
  # to disable the hidden id.
369
370
  #
370
- # In the following example the Post model has many Comments stored within it in a NoSQL database,
371
+ # In the following example the Article model has many Comments stored within it in a NoSQL database,
371
372
  # thus there is no primary key for comments.
372
373
  #
373
374
  # Example:
374
375
  #
375
- # <%= form_for(@post) do |f| %>
376
+ # <%= form_for(@article) do |f| %>
376
377
  # <%= f.fields_for(:comments, include_id: false) do |cf| %>
377
378
  # ...
378
379
  # <% end %>
@@ -436,7 +437,7 @@ module ActionView
436
437
 
437
438
  case record
438
439
  when String, Symbol
439
- model = nil
440
+ model = false
440
441
  object_name = record
441
442
  else
442
443
  model = record
@@ -484,12 +485,12 @@ module ActionView
484
485
  # Creates a form tag based on mixing URLs, scopes, or models.
485
486
  #
486
487
  # # Using just a URL:
487
- # <%= form_with url: posts_path do |form| %>
488
+ # <%= form_with url: articles_path do |form| %>
488
489
  # <%= form.text_field :title %>
489
490
  # <% end %>
490
491
  # # =>
491
- # <form action="/posts" method="post">
492
- # <input type="text" name="title">
492
+ # <form action="/articles" method="post">
493
+ # <input type="text" name="title" />
493
494
  # </form>
494
495
  #
495
496
  # # With an intentionally empty URL:
@@ -498,37 +499,36 @@ module ActionView
498
499
  # <% end %>
499
500
  # # =>
500
501
  # <form method="post">
501
- # <input type="text" name="title">
502
+ # <input type="text" name="title" />
502
503
  # </form>
503
504
  #
504
505
  # # Adding a scope prefixes the input field names:
505
- # <%= form_with scope: :post, url: posts_path do |form| %>
506
+ # <%= form_with scope: :article, url: articles_path do |form| %>
506
507
  # <%= form.text_field :title %>
507
508
  # <% end %>
508
509
  # # =>
509
- # <form action="/posts" method="post">
510
- # <input type="text" name="post[title]">
510
+ # <form action="/articles" method="post">
511
+ # <input type="text" name="article[title]" />
511
512
  # </form>
512
513
  #
513
514
  # # Using a model infers both the URL and scope:
514
- # <%= form_with model: Post.new do |form| %>
515
+ # <%= form_with model: Article.new do |form| %>
515
516
  # <%= form.text_field :title %>
516
517
  # <% end %>
517
518
  # # =>
518
- # <form action="/posts" method="post">
519
- # <input type="text" name="post[title]">
519
+ # <form action="/articles" method="post">
520
+ # <input type="text" name="article[title]" />
520
521
  # </form>
521
522
  #
522
523
  # # An existing model makes an update form and fills out field values:
523
- # <%= form_with model: Post.first do |form| %>
524
+ # <%= form_with model: Article.first do |form| %>
524
525
  # <%= form.text_field :title %>
525
526
  # <% end %>
526
527
  # # =>
527
- # <form action="/posts/1" method="post">
528
- # <input type="hidden" name="_method" value="patch">
529
- # <input type="text" name="post[title]" value="<the title of the post>">
528
+ # <form action="/articles/1" method="post">
529
+ # <input type="hidden" name="_method" value="patch" />
530
+ # <input type="text" name="article[title]" value="<the title of the article>" />
530
531
  # </form>
531
- #
532
532
  # # Though the fields don't have to correspond to model attributes:
533
533
  # <%= form_with model: Cat.new do |form| %>
534
534
  # <%= form.text_field :cats_dont_have_gills %>
@@ -536,13 +536,13 @@ module ActionView
536
536
  # <% end %>
537
537
  # # =>
538
538
  # <form action="/cats" method="post">
539
- # <input type="text" name="cat[cats_dont_have_gills]">
540
- # <input type="text" name="cat[but_in_forms_they_can]">
539
+ # <input type="text" name="cat[cats_dont_have_gills]" />
540
+ # <input type="text" name="cat[but_in_forms_they_can]" />
541
541
  # </form>
542
542
  #
543
543
  # The parameters in the forms are accessible in controllers according to
544
- # their name nesting. So inputs named +title+ and <tt>post[title]</tt> are
545
- # accessible as <tt>params[:title]</tt> and <tt>params[:post][:title]</tt>
544
+ # their name nesting. So inputs named +title+ and <tt>article[title]</tt> are
545
+ # accessible as <tt>params[:title]</tt> and <tt>params[:article][:title]</tt>
546
546
  # respectively.
547
547
  #
548
548
  # For ease of comparison the examples above left out the submit button,
@@ -558,25 +558,25 @@ module ActionView
558
558
  #
559
559
  # So when passing such a model record, \Rails infers the URL and method.
560
560
  #
561
- # <%= form_with model: @post do |form| %>
561
+ # <%= form_with model: @article do |form| %>
562
562
  # ...
563
563
  # <% end %>
564
564
  #
565
565
  # is then equivalent to something like:
566
566
  #
567
- # <%= form_with scope: :post, url: post_path(@post), method: :patch do |form| %>
567
+ # <%= form_with scope: :article, url: article_path(@article), method: :patch do |form| %>
568
568
  # ...
569
569
  # <% end %>
570
570
  #
571
571
  # And for a new record
572
572
  #
573
- # <%= form_with model: Post.new do |form| %>
573
+ # <%= form_with model: Article.new do |form| %>
574
574
  # ...
575
575
  # <% end %>
576
576
  #
577
577
  # is equivalent to something like:
578
578
  #
579
- # <%= form_with scope: :post, url: posts_path do |form| %>
579
+ # <%= form_with scope: :article, url: articles_path do |form| %>
580
580
  # ...
581
581
  # <% end %>
582
582
  #
@@ -605,7 +605,7 @@ module ActionView
605
605
  # If the model is a new record a create form is generated, if an
606
606
  # existing record, however, an update form is generated.
607
607
  # Pass <tt>:scope</tt> or <tt>:url</tt> to override the defaults.
608
- # E.g. turn <tt>params[:post]</tt> into <tt>params[:article]</tt>.
608
+ # E.g. turn <tt>params[:article]</tt> into <tt>params[:blog]</tt>.
609
609
  # * <tt>:authenticity_token</tt> - Authenticity token to use in the form.
610
610
  # Override with a custom authenticity token or pass <tt>false</tt> to
611
611
  # skip the authenticity token field altogether.
@@ -638,14 +638,14 @@ module ActionView
638
638
  #
639
639
  # When not passing a block, +form_with+ just generates an opening form tag.
640
640
  #
641
- # <%= form_with(model: @post, url: super_posts_path) %>
642
- # <%= form_with(model: @post, scope: :article) %>
643
- # <%= form_with(model: @post, format: :json) %>
644
- # <%= form_with(model: @post, authenticity_token: false) %> # Disables the token.
641
+ # <%= form_with(model: @article, url: super_articles_path) %>
642
+ # <%= form_with(model: @article, scope: :blog) %>
643
+ # <%= form_with(model: @article, format: :json) %>
644
+ # <%= form_with(model: @article, authenticity_token: false) %> # Disables the token.
645
645
  #
646
- # For namespaced routes, like +admin_post_url+:
646
+ # For namespaced routes, like +admin_article_url+:
647
647
  #
648
- # <%= form_with(model: [ :admin, @post ]) do |form| %>
648
+ # <%= form_with(model: [ :admin, @article ]) do |form| %>
649
649
  # ...
650
650
  # <% end %>
651
651
  #
@@ -693,13 +693,13 @@ module ActionView
693
693
  # You can set data attributes directly in a data hash, but HTML options
694
694
  # besides id and class must be wrapped in an HTML key:
695
695
  #
696
- # <%= form_with(model: @post, data: { behavior: "autosave" }, html: { name: "go" }) do |form| %>
696
+ # <%= form_with(model: @article, data: { behavior: "autosave" }, html: { name: "go" }) do |form| %>
697
697
  # ...
698
698
  # <% end %>
699
699
  #
700
700
  # generates
701
701
  #
702
- # <form action="/posts/123" method="post" data-behavior="autosave" name="go">
702
+ # <form action="/articles/123" method="post" data-behavior="autosave" name="go">
703
703
  # <input name="_method" type="hidden" value="patch" />
704
704
  # ...
705
705
  # </form>
@@ -711,10 +711,10 @@ module ActionView
711
711
  # Some ORM systems do not use IDs on nested models so in this case you want to be able
712
712
  # to disable the hidden id.
713
713
  #
714
- # In the following example the Post model has many Comments stored within it in a NoSQL database,
714
+ # In the following example the Article model has many Comments stored within it in a NoSQL database,
715
715
  # thus there is no primary key for comments.
716
716
  #
717
- # <%= form_with(model: @post) do |form| %>
717
+ # <%= form_with(model: @article) do |form| %>
718
718
  # <%= form.fields(:comments, skip_id: true) do |fields| %>
719
719
  # ...
720
720
  # <% end %>
@@ -752,7 +752,9 @@ module ActionView
752
752
  # def labelled_form_with(**options, &block)
753
753
  # form_with(**options.merge(builder: LabellingFormBuilder), &block)
754
754
  # end
755
- def form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
755
+ def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block)
756
+ ActionView.deprecator.warn("Passing nil to the :model argument is deprecated and will raise in Rails 8.0") if model.nil?
757
+
756
758
  options = { allow_method_names_outside_object: true, skip_default_ids: !form_with_generates_ids }.merge!(options)
757
759
 
758
760
  if model
@@ -781,23 +783,23 @@ module ActionView
781
783
  end
782
784
  end
783
785
 
784
- # Creates a scope around a specific model object like form_for, but
786
+ # Creates a scope around a specific model object like #form_with, but
785
787
  # doesn't create the form tags themselves. This makes fields_for suitable
786
788
  # for specifying additional model objects in the same form.
787
789
  #
788
- # Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
789
- # its method signature is slightly different. Like +form_for+, it yields
790
+ # Although the usage and purpose of +fields_for+ is similar to #form_with's,
791
+ # its method signature is slightly different. Like #form_with, it yields
790
792
  # a FormBuilder object associated with a particular model object to a block,
791
793
  # and within the block allows methods to be called on the builder to
792
794
  # generate fields associated with the model object. Fields may reflect
793
795
  # a model object in two ways - how they are named (hence how submitted
794
796
  # values appear within the +params+ hash in the controller) and what
795
- # default values are shown when the form the fields appear in is first
796
- # displayed. In order for both of these features to be specified independently,
797
+ # default values are shown when the form fields are first displayed.
798
+ # In order for both of these features to be specified independently,
797
799
  # both an object name (represented by either a symbol or string) and the
798
800
  # object itself can be passed to the method separately -
799
801
  #
800
- # <%= form_for @person do |person_form| %>
802
+ # <%= form_with model: @person do |person_form| %>
801
803
  # First name: <%= person_form.text_field :first_name %>
802
804
  # Last name : <%= person_form.text_field :last_name %>
803
805
  #
@@ -845,7 +847,7 @@ module ActionView
845
847
  # === Nested Attributes Examples
846
848
  #
847
849
  # When the object belonging to the current scope has a nested attribute
848
- # writer for a certain attribute, fields_for will yield a new scope
850
+ # writer for a certain attribute, +fields_for+ will yield a new scope
849
851
  # for that attribute. This allows you to create forms that set or change
850
852
  # the attributes of a parent object and its associations in one go.
851
853
  #
@@ -878,7 +880,7 @@ module ActionView
878
880
  #
879
881
  # This model can now be used with a nested fields_for, like so:
880
882
  #
881
- # <%= form_for @person do |person_form| %>
883
+ # <%= form_with model: @person do |person_form| %>
882
884
  # ...
883
885
  # <%= person_form.fields_for :address do |address_fields| %>
884
886
  # Street : <%= address_fields.text_field :street %>
@@ -908,7 +910,7 @@ module ActionView
908
910
  # with a value that evaluates to +true+, you will destroy the associated
909
911
  # model (e.g. 1, '1', true, or 'true'):
910
912
  #
911
- # <%= form_for @person do |person_form| %>
913
+ # <%= form_with model: @person do |person_form| %>
912
914
  # ...
913
915
  # <%= person_form.fields_for :address do |address_fields| %>
914
916
  # ...
@@ -934,7 +936,7 @@ module ActionView
934
936
  # end
935
937
  #
936
938
  # Note that the <tt>projects_attributes=</tt> writer method is in fact
937
- # required for fields_for to correctly identify <tt>:projects</tt> as a
939
+ # required for +fields_for+ to correctly identify <tt>:projects</tt> as a
938
940
  # collection, and the correct indices to be set in the form markup.
939
941
  #
940
942
  # When projects is already an association on Person you can use
@@ -946,10 +948,10 @@ module ActionView
946
948
  # end
947
949
  #
948
950
  # This model can now be used with a nested fields_for. The block given to
949
- # the nested fields_for call will be repeated for each instance in the
951
+ # the nested +fields_for+ call will be repeated for each instance in the
950
952
  # collection:
951
953
  #
952
- # <%= form_for @person do |person_form| %>
954
+ # <%= form_with model: @person do |person_form| %>
953
955
  # ...
954
956
  # <%= person_form.fields_for :projects do |project_fields| %>
955
957
  # <% if project_fields.object.active? %>
@@ -961,7 +963,7 @@ module ActionView
961
963
  #
962
964
  # It's also possible to specify the instance to be used:
963
965
  #
964
- # <%= form_for @person do |person_form| %>
966
+ # <%= form_with model: @person do |person_form| %>
965
967
  # ...
966
968
  # <% @person.projects.each do |project| %>
967
969
  # <% if project.active? %>
@@ -975,7 +977,7 @@ module ActionView
975
977
  #
976
978
  # Or a collection to be used:
977
979
  #
978
- # <%= form_for @person do |person_form| %>
980
+ # <%= form_with model: @person do |person_form| %>
979
981
  # ...
980
982
  # <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
981
983
  # Name: <%= project_fields.text_field :name %>
@@ -997,7 +999,7 @@ module ActionView
997
999
  # parameter with a value that evaluates to +true+
998
1000
  # (e.g. 1, '1', true, or 'true'):
999
1001
  #
1000
- # <%= form_for @person do |person_form| %>
1002
+ # <%= form_with model: @person do |person_form| %>
1001
1003
  # ...
1002
1004
  # <%= person_form.fields_for :projects do |project_fields| %>
1003
1005
  # Delete: <%= project_fields.check_box :_destroy %>
@@ -1006,10 +1008,10 @@ module ActionView
1006
1008
  # <% end %>
1007
1009
  #
1008
1010
  # When a collection is used you might want to know the index of each
1009
- # object into the array. For this purpose, the <tt>index</tt> method
1010
- # is available in the FormBuilder object.
1011
+ # object in the array. For this purpose, the <tt>index</tt> method is
1012
+ # available in the FormBuilder object.
1011
1013
  #
1012
- # <%= form_for @person do |person_form| %>
1014
+ # <%= form_with model: @person do |person_form| %>
1013
1015
  # ...
1014
1016
  # <%= person_form.fields_for :projects do |project_fields| %>
1015
1017
  # Project #<%= project_fields.index %>
@@ -1018,10 +1020,10 @@ module ActionView
1018
1020
  # ...
1019
1021
  # <% end %>
1020
1022
  #
1021
- # Note that fields_for will automatically generate a hidden field
1023
+ # Note that +fields_for+ will automatically generate a hidden field
1022
1024
  # to store the ID of the record if it responds to <tt>persisted?</tt>.
1023
1025
  # There are circumstances where this hidden field is not needed and you
1024
- # can pass <tt>include_id: false</tt> to prevent fields_for from
1026
+ # can pass <tt>include_id: false</tt> to prevent +fields_for+ from
1025
1027
  # rendering it automatically.
1026
1028
  def fields_for(record_name, record_object = nil, options = {}, &block)
1027
1029
  options = { model: record_object, allow_method_names_outside_object: false, skip_default_ids: false }.merge!(options)
@@ -1030,7 +1032,7 @@ module ActionView
1030
1032
  end
1031
1033
 
1032
1034
  # Scopes input fields with either an explicit scope or model.
1033
- # Like +form_with+ does with <tt>:scope</tt> or <tt>:model</tt>,
1035
+ # Like #form_with does with <tt>:scope</tt> or <tt>:model</tt>,
1034
1036
  # except it doesn't output the form tags.
1035
1037
  #
1036
1038
  # # Using a scope prefixes the input field names:
@@ -1045,8 +1047,8 @@ module ActionView
1045
1047
  # <% end %>
1046
1048
  # # => <input type="text" name="comment[body]" value="full bodied">
1047
1049
  #
1048
- # # Using +fields+ with +form_with+:
1049
- # <%= form_with model: @post do |form| %>
1050
+ # # Using `fields` with `form_with`:
1051
+ # <%= form_with model: @article do |form| %>
1050
1052
  # <%= form.text_field :title %>
1051
1053
  #
1052
1054
  # <%= form.fields :comment do |fields| %>
@@ -1054,13 +1056,13 @@ module ActionView
1054
1056
  # <% end %>
1055
1057
  # <% end %>
1056
1058
  #
1057
- # Much like +form_with+ a FormBuilder instance associated with the scope
1059
+ # Much like #form_with a FormBuilder instance associated with the scope
1058
1060
  # or model is yielded, so any generated field names are prefixed with
1059
1061
  # either the passed scope or the scope inferred from the <tt>:model</tt>.
1060
1062
  #
1061
1063
  # === Mixing with other form helpers
1062
1064
  #
1063
- # While +form_with+ uses a FormBuilder object it's possible to mix and
1065
+ # While #form_with uses a FormBuilder object it's possible to mix and
1064
1066
  # match the stand-alone FormHelper methods and methods
1065
1067
  # from FormTagHelper:
1066
1068
  #
@@ -1094,56 +1096,58 @@ module ActionView
1094
1096
  # target labels for radio_button tags (where the value is used in the ID of the input tag).
1095
1097
  #
1096
1098
  # ==== Examples
1097
- # label(:post, :title)
1098
- # # => <label for="post_title">Title</label>
1099
+ # label(:article, :title)
1100
+ # # => <label for="article_title">Title</label>
1099
1101
  #
1100
1102
  # You can localize your labels based on model and attribute names.
1101
1103
  # For example you can define the following in your locale (e.g. en.yml)
1102
1104
  #
1103
1105
  # helpers:
1104
1106
  # label:
1105
- # post:
1107
+ # article:
1106
1108
  # body: "Write your entire text here"
1107
1109
  #
1108
1110
  # Which then will result in
1109
1111
  #
1110
- # label(:post, :body)
1111
- # # => <label for="post_body">Write your entire text here</label>
1112
+ # label(:article, :body)
1113
+ # # => <label for="article_body">Write your entire text here</label>
1112
1114
  #
1113
1115
  # Localization can also be based purely on the translation of the attribute-name
1114
1116
  # (if you are using ActiveRecord):
1115
1117
  #
1116
1118
  # activerecord:
1117
1119
  # attributes:
1118
- # post:
1120
+ # article:
1119
1121
  # cost: "Total cost"
1120
1122
  #
1121
- # label(:post, :cost)
1122
- # # => <label for="post_cost">Total cost</label>
1123
+ # <code></code>
1124
+ #
1125
+ # label(:article, :cost)
1126
+ # # => <label for="article_cost">Total cost</label>
1123
1127
  #
1124
- # label(:post, :title, "A short title")
1125
- # # => <label for="post_title">A short title</label>
1128
+ # label(:article, :title, "A short title")
1129
+ # # => <label for="article_title">A short title</label>
1126
1130
  #
1127
- # label(:post, :title, "A short title", class: "title_label")
1128
- # # => <label for="post_title" class="title_label">A short title</label>
1131
+ # label(:article, :title, "A short title", class: "title_label")
1132
+ # # => <label for="article_title" class="title_label">A short title</label>
1129
1133
  #
1130
- # label(:post, :privacy, "Public Post", value: "public")
1131
- # # => <label for="post_privacy_public">Public Post</label>
1134
+ # label(:article, :privacy, "Public Article", value: "public")
1135
+ # # => <label for="article_privacy_public">Public Article</label>
1132
1136
  #
1133
- # label(:post, :cost) do |translation|
1137
+ # label(:article, :cost) do |translation|
1134
1138
  # content_tag(:span, translation, class: "cost_label")
1135
1139
  # end
1136
- # # => <label for="post_cost"><span class="cost_label">Total cost</span></label>
1140
+ # # => <label for="article_cost"><span class="cost_label">Total cost</span></label>
1137
1141
  #
1138
- # label(:post, :cost) do |builder|
1142
+ # label(:article, :cost) do |builder|
1139
1143
  # content_tag(:span, builder.translation, class: "cost_label")
1140
1144
  # end
1141
- # # => <label for="post_cost"><span class="cost_label">Total cost</span></label>
1145
+ # # => <label for="article_cost"><span class="cost_label">Total cost</span></label>
1142
1146
  #
1143
- # label(:post, :terms) do
1147
+ # label(:article, :terms) do
1144
1148
  # raw('Accept <a href="/terms">Terms</a>.')
1145
1149
  # end
1146
- # # => <label for="post_terms">Accept <a href="/terms">Terms</a>.</label>
1150
+ # # => <label for="article_terms">Accept <a href="/terms">Terms</a>.</label>
1147
1151
  def label(object_name, method, content_or_options = nil, options = nil, &block)
1148
1152
  Tags::Label.new(object_name, method, self, content_or_options, options).render(&block)
1149
1153
  end
@@ -1154,14 +1158,14 @@ module ActionView
1154
1158
  # shown.
1155
1159
  #
1156
1160
  # ==== Examples
1157
- # text_field(:post, :title, size: 20)
1158
- # # => <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />
1161
+ # text_field(:article, :title, size: 20)
1162
+ # # => <input type="text" id="article_title" name="article[title]" size="20" value="#{@article.title}" />
1159
1163
  #
1160
- # text_field(:post, :title, class: "create_input")
1161
- # # => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" class="create_input" />
1164
+ # text_field(:article, :title, class: "create_input")
1165
+ # # => <input type="text" id="article_title" name="article[title]" value="#{@article.title}" class="create_input" />
1162
1166
  #
1163
- # text_field(:post, :title, maxlength: 30, class: "title_input")
1164
- # # => <input type="text" id="post_title" name="post[title]" maxlength="30" size="30" value="#{@post.title}" class="title_input" />
1167
+ # text_field(:article, :title, maxlength: 30, class: "title_input")
1168
+ # # => <input type="text" id="article_title" name="article[title]" maxlength="30" size="30" value="#{@article.title}" class="title_input" />
1165
1169
  #
1166
1170
  # text_field(:session, :user, onchange: "if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }")
1167
1171
  # # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange="if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }"/>
@@ -1202,8 +1206,8 @@ module ActionView
1202
1206
  # hidden_field(:signup, :pass_confirm)
1203
1207
  # # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="#{@signup.pass_confirm}" />
1204
1208
  #
1205
- # hidden_field(:post, :tag_list)
1206
- # # => <input type="hidden" id="post_tag_list" name="post[tag_list]" value="#{@post.tag_list}" />
1209
+ # hidden_field(:article, :tag_list)
1210
+ # # => <input type="hidden" id="article_tag_list" name="article[tag_list]" value="#{@article.tag_list}" />
1207
1211
  #
1208
1212
  # hidden_field(:user, :token)
1209
1213
  # # => <input type="hidden" id="user_token" name="user[token]" value="#{@user.token}" />
@@ -1216,7 +1220,7 @@ module ActionView
1216
1220
  # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
1217
1221
  # shown.
1218
1222
  #
1219
- # Using this method inside a +form_for+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
1223
+ # Using this method inside a #form_with block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
1220
1224
  #
1221
1225
  # ==== Options
1222
1226
  # * Creates standard HTML attributes for the tag.
@@ -1229,14 +1233,14 @@ module ActionView
1229
1233
  # file_field(:user, :avatar)
1230
1234
  # # => <input type="file" id="user_avatar" name="user[avatar]" />
1231
1235
  #
1232
- # file_field(:post, :image, multiple: true)
1233
- # # => <input type="file" id="post_image" name="post[image][]" multiple="multiple" />
1236
+ # file_field(:article, :image, multiple: true)
1237
+ # # => <input type="file" id="article_image" name="article[image][]" multiple="multiple" />
1234
1238
  #
1235
- # file_field(:post, :attached, accept: 'text/html')
1236
- # # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
1239
+ # file_field(:article, :attached, accept: 'text/html')
1240
+ # # => <input accept="text/html" type="file" id="article_attached" name="article[attached]" />
1237
1241
  #
1238
- # file_field(:post, :image, accept: 'image/png,image/gif,image/jpeg')
1239
- # # => <input type="file" id="post_image" name="post[image]" accept="image/png,image/gif,image/jpeg" />
1242
+ # file_field(:article, :image, accept: 'image/png,image/gif,image/jpeg')
1243
+ # # => <input type="file" id="article_image" name="article[image]" accept="image/png,image/gif,image/jpeg" />
1240
1244
  #
1241
1245
  # file_field(:attachment, :file, class: 'file_input')
1242
1246
  # # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
@@ -1251,9 +1255,9 @@ module ActionView
1251
1255
  # hash with +options+.
1252
1256
  #
1253
1257
  # ==== Examples
1254
- # text_area(:post, :body, cols: 20, rows: 40)
1255
- # # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
1256
- # # #{@post.body}
1258
+ # text_area(:article, :body, cols: 20, rows: 40)
1259
+ # # => <textarea cols="20" rows="40" id="article_body" name="article[body]">
1260
+ # # #{@article.body}
1257
1261
  # # </textarea>
1258
1262
  #
1259
1263
  # text_area(:comment, :text, size: "20x30")
@@ -1320,15 +1324,15 @@ module ActionView
1320
1324
  # the elements of the array. For each item with a checked check box you
1321
1325
  # get an extra ghost item with only that attribute, assigned to "0".
1322
1326
  #
1323
- # In that case it is preferable to either use +check_box_tag+ or to use
1327
+ # In that case it is preferable to either use FormTagHelper#check_box_tag or to use
1324
1328
  # hashes instead of arrays.
1325
1329
  #
1326
1330
  # ==== Examples
1327
1331
  #
1328
- # # Let's say that @post.validated? is 1:
1329
- # check_box("post", "validated")
1330
- # # => <input name="post[validated]" type="hidden" value="0" />
1331
- # # <input checked="checked" type="checkbox" id="post_validated" name="post[validated]" value="1" />
1332
+ # # Let's say that @article.validated? is 1:
1333
+ # check_box("article", "validated")
1334
+ # # => <input name="article[validated]" type="hidden" value="0" />
1335
+ # # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
1332
1336
  #
1333
1337
  # # Let's say that @puppy.gooddog is "no":
1334
1338
  # check_box("puppy", "gooddog", {}, "yes", "no")
@@ -1349,11 +1353,11 @@ module ActionView
1349
1353
  # To force the radio button to be checked pass <tt>checked: true</tt> in the
1350
1354
  # +options+ hash. You may pass HTML options there as well.
1351
1355
  #
1352
- # # Let's say that @post.category returns "rails":
1353
- # radio_button("post", "category", "rails")
1354
- # radio_button("post", "category", "java")
1355
- # # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" />
1356
- # # <input type="radio" id="post_category_java" name="post[category]" value="java" />
1356
+ # # Let's say that @article.category returns "rails":
1357
+ # radio_button("article", "category", "rails")
1358
+ # radio_button("article", "category", "java")
1359
+ # # => <input type="radio" id="article_category_rails" name="article[category]" value="rails" checked="checked" />
1360
+ # # <input type="radio" id="article_category_java" name="article[category]" value="java" />
1357
1361
  #
1358
1362
  # # Let's say that @user.receive_newsletter returns "no":
1359
1363
  # radio_button("user", "receive_newsletter", "yes")
@@ -1625,10 +1629,10 @@ module ActionView
1625
1629
  #
1626
1630
  # A +FormBuilder+ object is associated with a particular model object and
1627
1631
  # allows you to generate fields associated with the model object. The
1628
- # +FormBuilder+ object is yielded when using +form_for+ or +fields_for+.
1632
+ # +FormBuilder+ object is yielded when using #form_with or #fields_for.
1629
1633
  # For example:
1630
1634
  #
1631
- # <%= form_for @person do |person_form| %>
1635
+ # <%= form_with model: @person do |person_form| %>
1632
1636
  # Name: <%= person_form.text_field :name %>
1633
1637
  # Admin: <%= person_form.check_box :admin %>
1634
1638
  # <% end %>
@@ -1664,7 +1668,7 @@ module ActionView
1664
1668
  #
1665
1669
  # The +div_radio_button+ code from above can now be used as follows:
1666
1670
  #
1667
- # <%= form_for @person, :builder => MyFormBuilder do |f| %>
1671
+ # <%= form_with model: @person, :builder => MyFormBuilder do |f| %>
1668
1672
  # I am a child: <%= f.div_radio_button(:admin, "child") %>
1669
1673
  # I am an adult: <%= f.div_radio_button(:admin, "adult") %>
1670
1674
  # <% end -%>
@@ -1734,7 +1738,7 @@ module ActionView
1734
1738
  #
1735
1739
  # return the <tt><form></tt> element's <tt>id</tt> attribute.
1736
1740
  #
1737
- # <%= form_for @post do |f| %>
1741
+ # <%= form_with model: @article do |f| %>
1738
1742
  # <%# ... %>
1739
1743
  #
1740
1744
  # <% content_for :sticky_footer do %>
@@ -1756,16 +1760,16 @@ module ActionView
1756
1760
  # Return the value generated by the <tt>FormBuilder</tt> for the given
1757
1761
  # attribute name.
1758
1762
  #
1759
- # <%= form_for @post do |f| %>
1763
+ # <%= form_with model: @article do |f| %>
1760
1764
  # <%= f.label :title %>
1761
1765
  # <%= f.text_field :title, aria: { describedby: f.field_id(:title, :error) } %>
1762
1766
  # <%= tag.span("is blank", id: f.field_id(:title, :error) %>
1763
1767
  # <% end %>
1764
1768
  #
1765
1769
  # In the example above, the <tt><input type="text"></tt> element built by
1766
- # the call to <tt>FormBuilder#text_field</tt> declares an
1770
+ # the call to #text_field declares an
1767
1771
  # <tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
1768
- # element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
1772
+ # element, sharing a common <tt>id</tt> root (<tt>article_title</tt>, in this
1769
1773
  # case).
1770
1774
  def field_id(method, *suffixes, namespace: @options[:namespace], index: @options[:index])
1771
1775
  @template.field_id(@object_name, method, *suffixes, namespace: namespace, index: index)
@@ -1777,14 +1781,14 @@ module ActionView
1777
1781
  # Return the value generated by the <tt>FormBuilder</tt> for the given
1778
1782
  # attribute name.
1779
1783
  #
1780
- # <%= form_for @post do |f| %>
1784
+ # <%= form_with model: @article do |f| %>
1781
1785
  # <%= f.text_field :title, name: f.field_name(:title, :subtitle) %>
1782
- # <%# => <input type="text" name="post[title][subtitle]">
1786
+ # <%# => <input type="text" name="article[title][subtitle]"> %>
1783
1787
  # <% end %>
1784
1788
  #
1785
- # <%= form_for @post do |f| %>
1786
- # <%= f.field_tag :tag, name: f.field_name(:tag, multiple: true) %>
1787
- # <%# => <input type="text" name="post[tag][]">
1789
+ # <%= form_with model: @article do |f| %>
1790
+ # <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
1791
+ # <%# => <input type="text" name="article[tag][]"> %>
1788
1792
  # <% end %>
1789
1793
  #
1790
1794
  def field_name(method, *methods, multiple: false, index: @options[:index])
@@ -2014,35 +2018,39 @@ module ActionView
2014
2018
  #
2015
2019
  # Please refer to the documentation of the base helper for details.
2016
2020
 
2017
- (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
2018
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
2019
- def #{selector}(method, options = {}) # def text_field(method, options = {})
2020
- @template.public_send( # @template.public_send(
2021
- #{selector.inspect}, # :text_field,
2022
- @object_name, # @object_name,
2023
- method, # method,
2024
- objectify_options(options)) # objectify_options(options))
2025
- end # end
2026
- RUBY_EVAL
2021
+ ActiveSupport::CodeGenerator.batch(self, __FILE__, __LINE__) do |code_generator|
2022
+ (field_helpers - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field]).each do |selector|
2023
+ code_generator.define_cached_method(selector, namespace: :form_builder) do |batch|
2024
+ batch.push <<-RUBY_EVAL
2025
+ def #{selector}(method, options = {}) # def text_field(method, options = {})
2026
+ @template.public_send( # @template.public_send(
2027
+ #{selector.inspect}, # :text_field,
2028
+ @object_name, # @object_name,
2029
+ method, # method,
2030
+ objectify_options(options)) # objectify_options(options))
2031
+ end # end
2032
+ RUBY_EVAL
2033
+ end
2034
+ end
2027
2035
  end
2028
2036
 
2029
- # Creates a scope around a specific model object like form_for, but
2037
+ # Creates a scope around a specific model object like #form_with, but
2030
2038
  # doesn't create the form tags themselves. This makes fields_for suitable
2031
2039
  # for specifying additional model objects in the same form.
2032
2040
  #
2033
- # Although the usage and purpose of +fields_for+ is similar to +form_for+'s,
2034
- # its method signature is slightly different. Like +form_for+, it yields
2041
+ # Although the usage and purpose of +fields_for+ is similar to #form_with's,
2042
+ # its method signature is slightly different. Like #form_with, it yields
2035
2043
  # a FormBuilder object associated with a particular model object to a block,
2036
2044
  # and within the block allows methods to be called on the builder to
2037
2045
  # generate fields associated with the model object. Fields may reflect
2038
2046
  # a model object in two ways - how they are named (hence how submitted
2039
2047
  # values appear within the +params+ hash in the controller) and what
2040
- # default values are shown when the form the fields appear in is first
2041
- # displayed. In order for both of these features to be specified independently,
2048
+ # default values are shown when the form fields are first displayed.
2049
+ # In order for both of these features to be specified independently,
2042
2050
  # both an object name (represented by either a symbol or string) and the
2043
2051
  # object itself can be passed to the method separately -
2044
2052
  #
2045
- # <%= form_for @person do |person_form| %>
2053
+ # <%= form_with model: @person do |person_form| %>
2046
2054
  # First name: <%= person_form.text_field :first_name %>
2047
2055
  # Last name : <%= person_form.text_field :last_name %>
2048
2056
  #
@@ -2091,7 +2099,7 @@ module ActionView
2091
2099
  # name and value parameters are provided and the provided value has the shape of an
2092
2100
  # option Hash. To remove the ambiguity, explicitly pass an option Hash, even if empty.
2093
2101
  #
2094
- # <%= form_for @person do |person_form| %>
2102
+ # <%= form_with model: @person do |person_form| %>
2095
2103
  # ...
2096
2104
  # <%= fields_for :permission, @person.permission, {} do |permission_fields| %>
2097
2105
  # Admin?: <%= check_box_tag permission_fields.field_name(:admin), @person.permission[:admin] %>
@@ -2102,7 +2110,7 @@ module ActionView
2102
2110
  # === Nested Attributes Examples
2103
2111
  #
2104
2112
  # When the object belonging to the current scope has a nested attribute
2105
- # writer for a certain attribute, fields_for will yield a new scope
2113
+ # writer for a certain attribute, +fields_for+ will yield a new scope
2106
2114
  # for that attribute. This allows you to create forms that set or change
2107
2115
  # the attributes of a parent object and its associations in one go.
2108
2116
  #
@@ -2133,9 +2141,9 @@ module ActionView
2133
2141
  # end
2134
2142
  # end
2135
2143
  #
2136
- # This model can now be used with a nested fields_for, like so:
2144
+ # This model can now be used with a nested +fields_for+, like so:
2137
2145
  #
2138
- # <%= form_for @person do |person_form| %>
2146
+ # <%= form_with model: @person do |person_form| %>
2139
2147
  # ...
2140
2148
  # <%= person_form.fields_for :address do |address_fields| %>
2141
2149
  # Street : <%= address_fields.text_field :street %>
@@ -2165,7 +2173,7 @@ module ActionView
2165
2173
  # with a value that evaluates to +true+, you will destroy the associated
2166
2174
  # model (e.g. 1, '1', true, or 'true'):
2167
2175
  #
2168
- # <%= form_for @person do |person_form| %>
2176
+ # <%= form_with model: @person do |person_form| %>
2169
2177
  # ...
2170
2178
  # <%= person_form.fields_for :address do |address_fields| %>
2171
2179
  # ...
@@ -2191,7 +2199,7 @@ module ActionView
2191
2199
  # end
2192
2200
  #
2193
2201
  # Note that the <tt>projects_attributes=</tt> writer method is in fact
2194
- # required for fields_for to correctly identify <tt>:projects</tt> as a
2202
+ # required for +fields_for+ to correctly identify <tt>:projects</tt> as a
2195
2203
  # collection, and the correct indices to be set in the form markup.
2196
2204
  #
2197
2205
  # When projects is already an association on Person you can use
@@ -2202,11 +2210,11 @@ module ActionView
2202
2210
  # accepts_nested_attributes_for :projects
2203
2211
  # end
2204
2212
  #
2205
- # This model can now be used with a nested fields_for. The block given to
2206
- # the nested fields_for call will be repeated for each instance in the
2213
+ # This model can now be used with a nested +fields_for+. The block given to
2214
+ # the nested +fields_for+ call will be repeated for each instance in the
2207
2215
  # collection:
2208
2216
  #
2209
- # <%= form_for @person do |person_form| %>
2217
+ # <%= form_with model: @person do |person_form| %>
2210
2218
  # ...
2211
2219
  # <%= person_form.fields_for :projects do |project_fields| %>
2212
2220
  # <% if project_fields.object.active? %>
@@ -2218,7 +2226,7 @@ module ActionView
2218
2226
  #
2219
2227
  # It's also possible to specify the instance to be used:
2220
2228
  #
2221
- # <%= form_for @person do |person_form| %>
2229
+ # <%= form_with model: @person do |person_form| %>
2222
2230
  # ...
2223
2231
  # <% @person.projects.each do |project| %>
2224
2232
  # <% if project.active? %>
@@ -2232,7 +2240,7 @@ module ActionView
2232
2240
  #
2233
2241
  # Or a collection to be used:
2234
2242
  #
2235
- # <%= form_for @person do |person_form| %>
2243
+ # <%= form_with model: @person do |person_form| %>
2236
2244
  # ...
2237
2245
  # <%= person_form.fields_for :projects, @active_projects do |project_fields| %>
2238
2246
  # Name: <%= project_fields.text_field :name %>
@@ -2254,7 +2262,7 @@ module ActionView
2254
2262
  # parameter with a value that evaluates to +true+
2255
2263
  # (e.g. 1, '1', true, or 'true'):
2256
2264
  #
2257
- # <%= form_for @person do |person_form| %>
2265
+ # <%= form_with model: @person do |person_form| %>
2258
2266
  # ...
2259
2267
  # <%= person_form.fields_for :projects do |project_fields| %>
2260
2268
  # Delete: <%= project_fields.check_box :_destroy %>
@@ -2263,10 +2271,10 @@ module ActionView
2263
2271
  # <% end %>
2264
2272
  #
2265
2273
  # When a collection is used you might want to know the index of each
2266
- # object into the array. For this purpose, the <tt>index</tt> method
2274
+ # object in the array. For this purpose, the <tt>index</tt> method
2267
2275
  # is available in the FormBuilder object.
2268
2276
  #
2269
- # <%= form_for @person do |person_form| %>
2277
+ # <%= form_with model: @person do |person_form| %>
2270
2278
  # ...
2271
2279
  # <%= person_form.fields_for :projects do |project_fields| %>
2272
2280
  # Project #<%= project_fields.index %>
@@ -2275,10 +2283,10 @@ module ActionView
2275
2283
  # ...
2276
2284
  # <% end %>
2277
2285
  #
2278
- # Note that fields_for will automatically generate a hidden field
2286
+ # Note that +fields_for+ will automatically generate a hidden field
2279
2287
  # to store the ID of the record. There are circumstances where this
2280
2288
  # hidden field is not needed and you can pass <tt>include_id: false</tt>
2281
- # to prevent fields_for from rendering it automatically.
2289
+ # to prevent +fields_for+ from rendering it automatically.
2282
2290
  def fields_for(record_name, record_object = nil, fields_options = nil, &block)
2283
2291
  fields_options, record_object = record_object, nil if fields_options.nil? && record_object.is_a?(Hash) && record_object.extractable_options?
2284
2292
  fields_options ||= {}
@@ -2335,50 +2343,52 @@ module ActionView
2335
2343
  #
2336
2344
  # ==== Examples
2337
2345
  # label(:title)
2338
- # # => <label for="post_title">Title</label>
2346
+ # # => <label for="article_title">Title</label>
2339
2347
  #
2340
2348
  # You can localize your labels based on model and attribute names.
2341
2349
  # For example you can define the following in your locale (e.g. en.yml)
2342
2350
  #
2343
2351
  # helpers:
2344
2352
  # label:
2345
- # post:
2353
+ # article:
2346
2354
  # body: "Write your entire text here"
2347
2355
  #
2348
2356
  # Which then will result in
2349
2357
  #
2350
2358
  # label(:body)
2351
- # # => <label for="post_body">Write your entire text here</label>
2359
+ # # => <label for="article_body">Write your entire text here</label>
2352
2360
  #
2353
2361
  # Localization can also be based purely on the translation of the attribute-name
2354
2362
  # (if you are using ActiveRecord):
2355
2363
  #
2356
2364
  # activerecord:
2357
2365
  # attributes:
2358
- # post:
2366
+ # article:
2359
2367
  # cost: "Total cost"
2360
2368
  #
2369
+ # <code></code>
2370
+ #
2361
2371
  # label(:cost)
2362
- # # => <label for="post_cost">Total cost</label>
2372
+ # # => <label for="article_cost">Total cost</label>
2363
2373
  #
2364
2374
  # label(:title, "A short title")
2365
- # # => <label for="post_title">A short title</label>
2375
+ # # => <label for="article_title">A short title</label>
2366
2376
  #
2367
2377
  # label(:title, "A short title", class: "title_label")
2368
- # # => <label for="post_title" class="title_label">A short title</label>
2378
+ # # => <label for="article_title" class="title_label">A short title</label>
2369
2379
  #
2370
- # label(:privacy, "Public Post", value: "public")
2371
- # # => <label for="post_privacy_public">Public Post</label>
2380
+ # label(:privacy, "Public Article", value: "public")
2381
+ # # => <label for="article_privacy_public">Public Article</label>
2372
2382
  #
2373
2383
  # label(:cost) do |translation|
2374
2384
  # content_tag(:span, translation, class: "cost_label")
2375
2385
  # end
2376
- # # => <label for="post_cost"><span class="cost_label">Total cost</span></label>
2386
+ # # => <label for="article_cost"><span class="cost_label">Total cost</span></label>
2377
2387
  #
2378
2388
  # label(:cost) do |builder|
2379
2389
  # content_tag(:span, builder.translation, class: "cost_label")
2380
2390
  # end
2381
- # # => <label for="post_cost"><span class="cost_label">Total cost</span></label>
2391
+ # # => <label for="article_cost"><span class="cost_label">Total cost</span></label>
2382
2392
  #
2383
2393
  # label(:cost) do |builder|
2384
2394
  # content_tag(:span, builder.translation, class: [
@@ -2386,12 +2396,12 @@ module ActionView
2386
2396
  # ("error_label" if builder.object.errors.include?(:cost))
2387
2397
  # ])
2388
2398
  # end
2389
- # # => <label for="post_cost"><span class="cost_label error_label">Total cost</span></label>
2399
+ # # => <label for="article_cost"><span class="cost_label error_label">Total cost</span></label>
2390
2400
  #
2391
2401
  # label(:terms) do
2392
2402
  # raw('Accept <a href="/terms">Terms</a>.')
2393
2403
  # end
2394
- # # => <label for="post_terms">Accept <a href="/terms">Terms</a>.</label>
2404
+ # # => <label for="article_terms">Accept <a href="/terms">Terms</a>.</label>
2395
2405
  def label(method, text = nil, options = {}, &block)
2396
2406
  @template.label(@object_name, method, text, objectify_options(options), &block)
2397
2407
  end
@@ -2442,15 +2452,15 @@ module ActionView
2442
2452
  # the elements of the array. For each item with a checked check box you
2443
2453
  # get an extra ghost item with only that attribute, assigned to "0".
2444
2454
  #
2445
- # In that case it is preferable to either use +check_box_tag+ or to use
2455
+ # In that case it is preferable to either use FormTagHelper#check_box_tag or to use
2446
2456
  # hashes instead of arrays.
2447
2457
  #
2448
2458
  # ==== Examples
2449
2459
  #
2450
- # # Let's say that @post.validated? is 1:
2460
+ # # Let's say that @article.validated? is 1:
2451
2461
  # check_box("validated")
2452
- # # => <input name="post[validated]" type="hidden" value="0" />
2453
- # # <input checked="checked" type="checkbox" id="post_validated" name="post[validated]" value="1" />
2462
+ # # => <input name="article[validated]" type="hidden" value="0" />
2463
+ # # <input checked="checked" type="checkbox" id="article_validated" name="article[validated]" value="1" />
2454
2464
  #
2455
2465
  # # Let's say that @puppy.gooddog is "no":
2456
2466
  # check_box("gooddog", {}, "yes", "no")
@@ -2472,11 +2482,11 @@ module ActionView
2472
2482
  # To force the radio button to be checked pass <tt>checked: true</tt> in the
2473
2483
  # +options+ hash. You may pass HTML options there as well.
2474
2484
  #
2475
- # # Let's say that @post.category returns "rails":
2485
+ # # Let's say that @article.category returns "rails":
2476
2486
  # radio_button("category", "rails")
2477
2487
  # radio_button("category", "java")
2478
- # # => <input type="radio" id="post_category_rails" name="post[category]" value="rails" checked="checked" />
2479
- # # <input type="radio" id="post_category_java" name="post[category]" value="java" />
2488
+ # # => <input type="radio" id="article_category_rails" name="article[category]" value="rails" checked="checked" />
2489
+ # # <input type="radio" id="article_category_java" name="article[category]" value="java" />
2480
2490
  #
2481
2491
  # # Let's say that @user.receive_newsletter returns "no":
2482
2492
  # radio_button("receive_newsletter", "yes")
@@ -2497,9 +2507,9 @@ module ActionView
2497
2507
  # hidden_field(:pass_confirm)
2498
2508
  # # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="true" />
2499
2509
  #
2500
- # # Let's say that @post.tag_list returns "blog, ruby":
2510
+ # # Let's say that @article.tag_list returns "blog, ruby":
2501
2511
  # hidden_field(:tag_list)
2502
- # # => <input type="hidden" id="post_tag_list" name="post[tag_list]" value="blog, ruby" />
2512
+ # # => <input type="hidden" id="article_tag_list" name="article[tag_list]" value="blog, ruby" />
2503
2513
  #
2504
2514
  # # Let's say that @user.token returns "abcde":
2505
2515
  # hidden_field(:token)
@@ -2515,7 +2525,7 @@ module ActionView
2515
2525
  # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
2516
2526
  # shown.
2517
2527
  #
2518
- # Using this method inside a +form_with+ block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
2528
+ # Using this method inside a #form_with block will set the enclosing form's encoding to <tt>multipart/form-data</tt>.
2519
2529
  #
2520
2530
  # ==== Options
2521
2531
  # * Creates standard HTML attributes for the tag.
@@ -2529,17 +2539,17 @@ module ActionView
2529
2539
  # file_field(:avatar)
2530
2540
  # # => <input type="file" id="user_avatar" name="user[avatar]" />
2531
2541
  #
2532
- # # Let's say that @post has image:
2542
+ # # Let's say that @article has image:
2533
2543
  # file_field(:image, :multiple => true)
2534
- # # => <input type="file" id="post_image" name="post[image][]" multiple="multiple" />
2544
+ # # => <input type="file" id="article_image" name="article[image][]" multiple="multiple" />
2535
2545
  #
2536
- # # Let's say that @post has attached:
2546
+ # # Let's say that @article has attached:
2537
2547
  # file_field(:attached, accept: 'text/html')
2538
- # # => <input accept="text/html" type="file" id="post_attached" name="post[attached]" />
2548
+ # # => <input accept="text/html" type="file" id="article_attached" name="article[attached]" />
2539
2549
  #
2540
- # # Let's say that @post has image:
2550
+ # # Let's say that @article has image:
2541
2551
  # file_field(:image, accept: 'image/png,image/gif,image/jpeg')
2542
- # # => <input type="file" id="post_image" name="post[image]" accept="image/png,image/gif,image/jpeg" />
2552
+ # # => <input type="file" id="article_image" name="article[image]" accept="image/png,image/gif,image/jpeg" />
2543
2553
  #
2544
2554
  # # Let's say that @attachment has file:
2545
2555
  # file_field(:file, class: 'file_input')
@@ -2552,12 +2562,12 @@ module ActionView
2552
2562
  # Add the submit button for the given form. When no value is given, it checks
2553
2563
  # if the object is a new resource or not to create the proper label:
2554
2564
  #
2555
- # <%= form_for @post do |f| %>
2565
+ # <%= form_with model: @article do |f| %>
2556
2566
  # <%= f.submit %>
2557
2567
  # <% end %>
2558
2568
  #
2559
- # In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
2560
- # submit button label; otherwise, it uses "Update Post".
2569
+ # In the example above, if <tt>@article</tt> is a new record, it will use "Create Article" as
2570
+ # submit button label; otherwise, it uses "Update Article".
2561
2571
  #
2562
2572
  # Those labels can be customized using I18n under the +helpers.submit+ key and using
2563
2573
  # <tt>%{model}</tt> for translation interpolation:
@@ -2573,7 +2583,7 @@ module ActionView
2573
2583
  # en:
2574
2584
  # helpers:
2575
2585
  # submit:
2576
- # post:
2586
+ # article:
2577
2587
  # create: "Add %{model}"
2578
2588
  #
2579
2589
  def submit(value = nil, options = {})
@@ -2585,12 +2595,11 @@ module ActionView
2585
2595
  # Add the submit button for the given form. When no value is given, it checks
2586
2596
  # if the object is a new resource or not to create the proper label:
2587
2597
  #
2588
- # <%= form_for @post do |f| %>
2598
+ # <%= form_with model: @article do |f| %>
2589
2599
  # <%= f.button %>
2590
2600
  # <% end %>
2591
- #
2592
- # In the example above, if <tt>@post</tt> is a new record, it will use "Create Post" as
2593
- # button label; otherwise, it uses "Update Post".
2601
+ # In the example above, if <tt>@article</tt> is a new record, it will use "Create Article" as
2602
+ # button label; otherwise, it uses "Update Article".
2594
2603
  #
2595
2604
  # Those labels can be customized using I18n under the +helpers.submit+ key
2596
2605
  # (the same as submit helper) and using <tt>%{model}</tt> for translation interpolation:
@@ -2606,15 +2615,15 @@ module ActionView
2606
2615
  # en:
2607
2616
  # helpers:
2608
2617
  # submit:
2609
- # post:
2618
+ # article:
2610
2619
  # create: "Add %{model}"
2611
2620
  #
2612
2621
  # ==== Examples
2613
- # button("Create post")
2614
- # # => <button name='button' type='submit'>Create post</button>
2622
+ # button("Create article")
2623
+ # # => <button name='button' type='submit'>Create article</button>
2615
2624
  #
2616
2625
  # button(:draft, value: true)
2617
- # # => <button id="post_draft" name="post[draft]" value="true" type="submit">Create post</button>
2626
+ # # => <button id="article_draft" name="article[draft]" value="true" type="submit">Create article</button>
2618
2627
  #
2619
2628
  # button do
2620
2629
  # content_tag(:strong, 'Ask me!')
@@ -2627,13 +2636,13 @@ module ActionView
2627
2636
  # content_tag(:strong, text)
2628
2637
  # end
2629
2638
  # # => <button name='button' type='submit'>
2630
- # # <strong>Create post</strong>
2639
+ # # <strong>Create article</strong>
2631
2640
  # # </button>
2632
2641
  #
2633
2642
  # button(:draft, value: true) do
2634
2643
  # content_tag(:strong, "Save as draft")
2635
2644
  # end
2636
- # # => <button id="post_draft" name="post[draft]" value="true" type="submit">
2645
+ # # => <button id="article_draft" name="article[draft]" value="true" type="submit">
2637
2646
  # # <strong>Save as draft</strong>
2638
2647
  # # </button>
2639
2648
  #