Repository navigation
Fix search_field raising NameError when passed autosave: true - #58336
Merged
fatkodima merged 1 commit intoAug 1, 2026
Merged
Conversation
fatkodima
reviewed
Aug 1, 2026
| @@ -1,3 +1,17 @@ | |||
| * Fix `search_field` raising `NameError` when passed `autosave: true`. | |||
|
|
|||
| `ActionView::Helpers::Tags::SearchField#render` called `request` on the tag | |||
Member
There was a problem hiding this comment.
I think the reader don't need to know these internal details. Can you delete them?
Contributor
Author
There was a problem hiding this comment.
Good call — trimmed it down to just the one-line summary, matching the surrounding entries. Thanks for the review!
`Tags::SearchField#render` resolves a `true` autosave value to the
reversed request host:
options["autosave"] = request.host.split(".").reverse.join(".")
But `Tags::Base` does not define `request` and does not delegate missing
methods to the view, so this raised
NameError: undefined local variable or method 'request'
for every caller, in every context. The `autosave: true` form is
documented on `search_field` with an expected output of
`autosave="com.example.www"`, so the documented behavior was unreachable.
Read the request from the view context instead, and add coverage for the
autosave branch: a `true` value, an explicit string, `results` not being
overridden when given, and `false` omitting `results` entirely.
hammadxcm
force-pushed
the
test-search-field-autosave-coverage
branch
from
August 1, 2026 20:24
43581b9 to
1d4780d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
search_fielddocuments anautosave: trueform that resolves to the reversed request host:That form has never worked.
ActionView::Helpers::Tags::SearchField#renderdoes:but
Tags::Baseneither definesrequestnor delegates missing methods to the view, so every call raises:This isn't context-dependent — the tag object has no
requestin any context, so the documented example raises for everyone. I found it while writing coverage for theautosavebranch, which turned out to be entirely untested; the two existingsearch_fieldtests only cover the plain call andonsearch: true.Fix
Read the request from the view context, which is what the tag already holds:
Tests
Added coverage for the whole
autosavebranch:autosave: trueresolves to the reversed host and defaultsresultsto10.autosavestring is passed through untouched, still defaultingresults.results:is not overridden.autosave: falserendersautosave="false"and omitsresults, matching the documented output.actionview—form_helper_test.rb,form_with_test.rb,form_options_helper_test.rb,form_tag_helper_test.rb: 832 runs, 1022 assertions, 0 failures, 0 errors. RuboCop clean.