mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Allow users to globally opt out of automatic lookup
This commit is contained in:
parent
8aaaa44ba3
commit
170db3ba88
@ -5,6 +5,7 @@ The following configuration options can be set on `ActiveModel::Serializer.confi
|
|||||||
## General
|
## General
|
||||||
|
|
||||||
- `adapter`: The [adapter](adapters.md) to use. Possible values: `:attributes, :json, :json_api`. Default: `:attributes`.
|
- `adapter`: The [adapter](adapters.md) to use. Possible values: `:attributes, :json, :json_api`. Default: `:attributes`.
|
||||||
|
- `automatic_lookup`: Whether serializer should be automatically looked up or manually provided. Default: `true`
|
||||||
|
|
||||||
## JSON API
|
## JSON API
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,10 @@ module ActionController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_serializer(resource, options = {})
|
def get_serializer(resource, options = {})
|
||||||
|
unless options[:serializer] || options[:each_serializer] || ActiveModel::Serializer.config.automatic_lookup
|
||||||
|
return resource
|
||||||
|
end
|
||||||
|
|
||||||
if !use_adapter?
|
if !use_adapter?
|
||||||
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
||||||
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
|
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
|
||||||
|
|||||||
@ -20,6 +20,7 @@ module ActiveModel
|
|||||||
|
|
||||||
config.adapter = :attributes
|
config.adapter = :attributes
|
||||||
config.jsonapi_resource_type = :plural
|
config.jsonapi_resource_type = :plural
|
||||||
|
config.automatic_lookup = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user