Skip to content

Commit 4f508a8

Browse files
committed
remove mime type registration, adjust key_transform advice
1 parent 8df5b04 commit 4f508a8

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

docs/integrations/ember-and-json-api.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,29 @@ To solve this, in Ember, both the adapter and the serializer will need some modi
2020
First, set the adapter type in an initializer file:
2121

2222
```ruby
23-
# config/initializers/ams_config.rb
23+
# config/initializers/active_model_serializers.rb
2424
ActiveModelSerializers.config.adapter = :json_api
2525
```
2626

2727
or:
2828

2929
```ruby
30-
# config/initializers/ams_config.rb
30+
# config/initializers/active_model_serializers.rb
3131
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
3232
```
3333

34-
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.
34+
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.
3535

3636
```ruby
37-
# config/initializers/ams_config.rb
38-
ActiveModelSerializers.config.key_transform = :underscore
37+
# config/initializers/active_model_serializers.rb
38+
ActiveModelSerializers.config.key_transform = :unaltered
3939
```
4040

41-
There are multiple mimetypes for json that should all be parsed similarly, so
42-
in `config/initializers/mime_types.rb`:
41+
Lastly, in order to properly handle JSON API responses, we need to register a JSON API renderer, like so:
4342

4443
```ruby
45-
api_mime_types = %W(
46-
application/vnd.api+json
47-
text/x-json
48-
application/json
49-
)
50-
51-
Mime::Type.unregister :json
52-
Mime::Type.register 'application/json', :json, api_mime_types
44+
# config/initializers/active_model_serializers.rb
45+
require 'active_model_serializers/register_jsonapi_renderer'
5346
```
5447

5548
### Adapter Changes

0 commit comments

Comments
 (0)