Configure ActionDispatch::Response#content_type
behavior on Rails 6+
#2340
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.
Purpose
This PR will affect all
#content_type
calls in the following files:active_model_serializers/test/action_controller/serialization_test.rb
Line 158 in 55a6b23
active_model_serializers/test/action_controller/explicit_serializer_test.rb
Line 74 in 55a6b23
Background
Rails 6 changes the default behavior of
ActionDispatch::Response#content_type
, which now returns the Content-Type header as it is.To retain old behavior, i.e. retrieve the mime type only, we can either set the following configuration in application settings:
or set it inline as:
or call
#media_type
instead of#content_type
.Additional helpful information
Rails 6.0 ACTIONPACK release notes:
https://github.com/rails/rails/blob/6-0-stable/actionpack/CHANGELOG.md
rails/rails#36490
rails/rails#36946