1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

In #4342, part of the functionalities of form_for was delegated to form_with, this could potentially cause some regress, as the condition to send polymorphic_path(record, {}) instead of polymorphic_path(record, format: options.delete(:format)) is removed and when format is not passed, this causes issues if the caller is not expecting an extra arg format:nil. This PR adds back the condition inside for with and add a test to make sure it doesn't break for_with

This commit is contained in:
Zhongying Qiao 2021-12-02 12:14:17 -08:00
parent 2b6182cbd6
commit c92ac83fe6
No known key found for this signature in database
GPG key ID: 5FC1402AD5967206
2 changed files with 17 additions and 1 deletions

View file

@ -754,7 +754,11 @@ module ActionView
if model
if url != false
url ||= polymorphic_path(model, format: format)
url ||= if format.nil?
polymorphic_path(model, {})
else
polymorphic_path(model, format: format)
end
end
model = _object_for_form_builder(model)

View file

@ -2057,6 +2057,18 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
def test_new_form_for_without_format
form_for(@post, html: { id: "edit_post_123", class: "edit_post" }) do |f|
concat f.label(:title)
end
expected = whole_form("/posts/123", "edit_post_123", "edit_post", method: "patch") do
"<label for='post_title'>Title</label>"
end
assert_dom_equal expected, output_buffer
end
def test_form_for_with_model_using_relative_model_naming
blog_post = Blog::Post.new("And his name will be forty and four.", 44)