Skip to content

Commit 46175a0

Browse files
committed
1 parent 9f98066 commit 46175a0

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

actionview/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Support `fields model: [@nested, @model]` the same way as `form_with model:
2+
[@nested, @model]`.
3+
4+
*Sean Doyle*
5+
16
* Add `:day_format` option to `date_select`
27

38
date_select("article", "written_on", day_format: ->(day) { day.ordinalize })

actionview/lib/action_view/helpers/form_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ def fields(scope = nil, model: nil, **options, &block)
10591059
options[:skip_default_ids] = !form_with_generates_ids
10601060

10611061
if model
1062+
model = model.last if model.is_a?(Array)
10621063
scope ||= model_name_from_record_or_class(model).param_key
10631064
end
10641065

actionview/test/template/form_helper/form_with_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,16 @@ def test_fields_with_only_object
20332033
assert_dom_equal expected, output_buffer
20342034
end
20352035

2036+
def test_fields_with_only_object_array
2037+
output_buffer = fields(model: [@post, @comment]) do |f|
2038+
concat f.text_field(:name)
2039+
end
2040+
2041+
expected = %(<input type="text" value="new comment" name="comment[name]" id="comment_name" />)
2042+
2043+
assert_dom_equal expected, output_buffer
2044+
end
2045+
20362046
def test_fields_object_with_bracketed_name
20372047
output_buffer = fields("author[post]", model: @post) do |f|
20382048
concat f.label(:title)

0 commit comments

Comments
 (0)