Use :unprocessable_content for scaffolds with Rack 3.1 or higher#603
Open
taketo1113 wants to merge 1 commit intorails:mainfrom
Open
Use :unprocessable_content for scaffolds with Rack 3.1 or higher#603taketo1113 wants to merge 1 commit intorails:mainfrom
:unprocessable_content for scaffolds with Rack 3.1 or higher#603taketo1113 wants to merge 1 commit intorails:mainfrom
Conversation
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.
Motivation / Background
In Rack v3.1.0, the symbol for HTTP status code 422 was changed from
:unprocessable_entityto:unprocessable_content.Rails supports both
:unprocessable_entityand:unprocessable_content, but for scaffolds generated when using Rack 3.1 or higher, it now uses:unprocessable_content.unprocessable_{entity,content}rails#53383Detail
This Pull Request updates controllers generated by scaffolds so that when using Rack v3.1 or higher, the HTTP status code returned in JSON format responses is changed from
:unprocessable_entityto:unprocessable_content, aligning with the behavior of Rails scaffolds.When using Rack v3.1 or higher, the generated scaffold code is updated as follows:
When using Rack v3.0 or lower, the generated code continues to use
:unprocessable_entityas before.Additional information
Since the jbuilder gem does not depend on actionpack (specifically action_dispatch) in its gemspec,
the choice between
:unprocessable_entityand:unprocessable_contentis determined by Rack (not byActionDispatch::Constants::UNPROCESSABLE_CONTENT):The behavior of
Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422)depends on the Rack version:The code for
Rack::Utils::SYMBOL_TO_STATUS_CODEcan be found here:https://github.com/rack/rack/blob/v3.2.1/lib/rack/utils.rb#L564-L566
https://github.com/rack/rack/blob/2.0.0/lib/rack/utils.rb#L581-L583