Guides > Global Configurations
Application-Wide Configurations
All the following configuration options can be set on
ActiveModelSerializers.config
, preferably in an initializer. For example, to setup the default
adapter:
# config/initializers/ams.rb
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
# or
ActiveModelSerializers.config.adapter = :json_api
# or
ActiveModelSerializers.config.adapter = :json
General Configurations
Configuration | Definition | Possible Values |
---|---|---|
adapter |
Which adapter to use |
|
serializer_lookup_enabled |
Enable automatic serializer lookup |
|
key_transform |
Modifys keys in serialized responses |
|
You can pass a
:key_transform
option to a specificrender
action. That will have priority over the globalkey_transform
configuration setting for the action.Key transforms can be expensive operations. If key transforms are unnecessary for the application, setting
config.key_transform
to:unaltered
will provide a performance boost.
Adapter-Specific Configurations
JSON API Adapter
Configuration | Definition | Possible Values |
---|---|---|
jsonapi_resource_type |
Whether type of the resource should be singularized or pluralized when not specified by the serializer |
|
jsonapi_include_toplevel_object |
Include a top level jsonapi member in the response document |
|
jsonapi_version |
Version of the spec to which the API conforms | '1.0' (default) |
jsonapi_toplevel_meta |
Top-level metadata. Not included if empty | {} (default) |
jsonapi_version
&jsonapi_toplevel_meta
are only used whenjsonapi_include_toplevel_object
istrue
Hooks
To run a hook when ActiveModelSerializers is loaded, in the initializer use
ActiveSupport.on_load(:action_controller) do
...
end