Skip to content

Commit

Permalink
Allow users to globally opt out of automatic lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Trek Glowacki committed Oct 23, 2015
1 parent f3403c3 commit 5a71255
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/general/configuration_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The following configuration options can be set on `ActiveModel::Serializer.confi
## General

- `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

Expand Down
4 changes: 4 additions & 0 deletions lib/action_controller/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def serialization_scope
end

def get_serializer(resource, options = {})
unless options[:serializer] || options[:each_serializer] || !ActiveModel::Serializer.config.automatic_lookup
return resource
end

if !use_adapter?
warn 'ActionController::Serialization#use_adapter? has been removed. '\
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
Expand Down
1 change: 1 addition & 0 deletions lib/active_model/serializer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def config.array_serializer

config.adapter = :attributes
config.jsonapi_resource_type = :plural
config.automatic_lookup = true
end
end
end
Expand Down

0 comments on commit 5a71255

Please sign in to comment.