Skip to content

Commit 846f9e9

Browse files
authored
Merge PR rails#43416
2 parents 4e06e83 + 46175a0 commit 846f9e9

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
* Infer HTTP verb `[method]` from a model or Array with model as the first
27
argument to `button_to` when combined with a block:
38

actionview/lib/action_view/helpers/form_helper.rb

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

10801080
if model
1081+
model = model.last if model.is_a?(Array)
10811082
scope ||= model_name_from_record_or_class(model).param_key
10821083
end
10831084

actionview/test/template/form_helper/form_with_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,16 @@ def test_fields_with_only_object
20652065
assert_dom_equal expected, output_buffer
20662066
end
20672067

2068+
def test_fields_with_only_object_array
2069+
output_buffer = fields(model: [@post, @comment]) do |f|
2070+
concat f.text_field(:name)
2071+
end
2072+
2073+
expected = %(<input type="text" value="new comment" name="comment[name]" id="comment_name" />)
2074+
2075+
assert_dom_equal expected, output_buffer
2076+
end
2077+
20682078
def test_fields_object_with_bracketed_name
20692079
output_buffer = fields("author[post]", model: @post) do |f|
20702080
concat f.label(:title)

0 commit comments

Comments
 (0)