Skip to content

Commit c029c00

Browse files
authored
Merge pull request #1802 from kyleshevlin/update_integrations_ember_and_json_api
update integration documentation for ember and JSONAPI to include…
2 parents f4e00dc + 4f508a8 commit c029c00

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,32 @@ To solve this, in Ember, both the adapter and the serializer will need some modi
1717

1818
### Server-Side Changes
1919

20-
there are multiple mimetypes for json that should all be parsed similarly, so
21-
in `config/initializers/mime_types.rb`:
20+
First, set the adapter type in an initializer file:
21+
22+
```ruby
23+
# config/initializers/active_model_serializers.rb
24+
ActiveModelSerializers.config.adapter = :json_api
25+
```
26+
27+
or:
28+
29+
```ruby
30+
# config/initializers/active_model_serializers.rb
31+
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
32+
```
33+
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.
35+
36+
```ruby
37+
# config/initializers/active_model_serializers.rb
38+
ActiveModelSerializers.config.key_transform = :unaltered
39+
```
40+
41+
Lastly, in order to properly handle JSON API responses, we need to register a JSON API renderer, like so:
42+
2243
```ruby
23-
api_mime_types = %W(
24-
application/vnd.api+json
25-
text/x-json
26-
application/json
27-
)
28-
29-
Mime::Type.unregister :json
30-
Mime::Type.register 'application/json', :json, api_mime_types
44+
# config/initializers/active_model_serializers.rb
45+
require 'active_model_serializers/register_jsonapi_renderer'
3146
```
3247

3348
### Adapter Changes

0 commit comments

Comments
 (0)