Adds a specific ArgumentError when passing nil to dom_id. #48987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
I created this PR to make invalid arguments passed to
dom_id
raise a specific error when it receives an invalid argument.For example with the following
dom_id(@something_non_existent)
Before this commit it would raise the following:
NoMethodError: undefined method 'to_key' for nil:NilClass
After it raises
ArumentError: dom_id must be passed a record_or_class as the first parameter, you passed 'nil'
Detail
This PR updates
dom_id
to validate it's argument and raise an ArgumentError whenever it is passed nil.The current
NoMethodError: undefined method 'to_key' for nil:NilClass
error is relatively difficult to identify what is going on because it occurs when the record is cast to a keyThe NoMethod error is raised when the argument that is passed to
dom_id
is sent torecord_key_for_dom_id
Passing a nil argument can happen in many scenarios, but a specific example is misspelling an instance variable
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]