Skip to content

Commit 9d0a913

Browse files
authored
Deprecate passing nil as model arg instead of raising ArgumentError (rails#50931)
1 parent e09e61a commit 9d0a913

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

actionview/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
*Sean Doyle*
1919

20-
* Raise `ArgumentError` when `nil` is passed as `model:` argument value to the `form_with` method.
20+
* Deprecate passing `nil` as value for the `model:` argument to the `form_with` method.
2121

2222
*Collin Jilbert*
2323

actionview/lib/action_view/helpers/form_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def apply_form_for_options!(object, options) # :nodoc:
754754
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
755755
# end
756756
def form_with(model: false, scope: nil, url: nil, format: nil, **options, &block)
757-
raise ArgumentError, "The :model argument cannot be nil" if model.nil?
757+
ActionView.deprecator.warn("Passing nil to the :model argument is deprecated and will raise in Rails 7.3") if model.nil?
758758

759759
options = { allow_method_names_outside_object: true, skip_default_ids: !form_with_generates_ids }.merge!(options)
760760

actionview/test/template/form_helper/form_with_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,10 @@ def url_for(object)
340340
end
341341

342342
def test_form_with_when_given_nil_model_argument
343-
error = assert_raises(ArgumentError) do
343+
assert_deprecated(ActionView.deprecator) do
344344
form_with(model: nil) do
345345
end
346346
end
347-
assert_equal "The :model argument cannot be nil", error.message
348347
end
349348

350349
def test_form_with

0 commit comments

Comments
 (0)