fix: ignore Accept header to prevent UnknownFormat errors#2585
Open
mroderick wants to merge 1 commit intocodebar:masterfrom
Open
fix: ignore Accept header to prevent UnknownFormat errors#2585mroderick wants to merge 1 commit intocodebar:masterfrom
mroderick wants to merge 1 commit intocodebar:masterfrom
Conversation
Prevents server errors when crawlers/scripts send non-HTML Accept headers. See: rails/rails@2f4aaed
KimberleyCook
approved these changes
Apr 22, 2026
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
config.action_dispatch.ignore_accept_header = trueto production environmentActionController::UnknownFormaterrors when clients send non-HTML Accept headers (e.g.,Accept: application/json)Problem
Requests with non-HTML Accept headers cause server errors:
Example error from production - AHC HTTP client requesting JSON:
Root Cause
Rails determines response format from (in priority order):
?format=query parameter.csv,.json)When a client sends
Accept: application/json, Rails tries to render JSON. Without JSON templates, it raisesUnknownFormat.Solution
Single configuration change in
config/environments/production.rb:This tells Rails to ignore the HTTP Accept header for format negotiation. Format comes only from:
?format=query parameter.csv,.json)How This Is Safe
What continues to work:
/admin/events/1.csv(path extension)/admin/events/1?format=text(query param)/admin/members/searchwhich explicitly renders JSON withrender json:What gets fixed:
Documentation
From the original Rails commit:
This is the recommended approach for public websites per Rails core team.