mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
remove mime type registration, adjust key_transform advice
This commit is contained in:
parent
8df5b045f2
commit
4f508a88c9
@ -20,36 +20,29 @@ To solve this, in Ember, both the adapter and the serializer will need some modi
|
|||||||
First, set the adapter type in an initializer file:
|
First, set the adapter type in an initializer file:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# config/initializers/ams_config.rb
|
# config/initializers/active_model_serializers.rb
|
||||||
ActiveModelSerializers.config.adapter = :json_api
|
ActiveModelSerializers.config.adapter = :json_api
|
||||||
```
|
```
|
||||||
|
|
||||||
or:
|
or:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# config/initializers/ams_config.rb
|
# config/initializers/active_model_serializers.rb
|
||||||
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
|
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
|
||||||
```
|
```
|
||||||
|
|
||||||
You will also want to set the `key_transform` to `:underscore` since you will adjust the attributes in your Ember serializer to use underscores instead of dashes later.
|
You will also want to set the `key_transform` to `:unaltered` since you will adjust the attributes in your Ember serializer to use underscores instead of dashes later. You could also use `:underscore`, but `:unaltered` is better for performance.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# config/initializers/ams_config.rb
|
# config/initializers/active_model_serializers.rb
|
||||||
ActiveModelSerializers.config.key_transform = :underscore
|
ActiveModelSerializers.config.key_transform = :unaltered
|
||||||
```
|
```
|
||||||
|
|
||||||
There are multiple mimetypes for json that should all be parsed similarly, so
|
Lastly, in order to properly handle JSON API responses, we need to register a JSON API renderer, like so:
|
||||||
in `config/initializers/mime_types.rb`:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
api_mime_types = %W(
|
# config/initializers/active_model_serializers.rb
|
||||||
application/vnd.api+json
|
require 'active_model_serializers/register_jsonapi_renderer'
|
||||||
text/x-json
|
|
||||||
application/json
|
|
||||||
)
|
|
||||||
|
|
||||||
Mime::Type.unregister :json
|
|
||||||
Mime::Type.register 'application/json', :json, api_mime_types
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adapter Changes
|
### Adapter Changes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user