It’s better to use the Active Model Adapter


When I started with this project I was trying to use the JSONAPI serializer and adapter that Ember has built in. This unfortunately was doomed to fail as I have a rails backend. Rails expects underscore between words while JSONAPI expects camelCase and so the two would never have lined up. I had set up a simple input page to try out POST calls to my rails backend. It was routing to the correct controller and action but no parameters were being sent. I checked my network tab in chrome and see that they were indeed sent, but a debugger on the rails showed no params.

Jumping straight to the answer I need to use the Active Model Adapater and Serializer. Their github page has some good docs to read through. Simply install it with:

ember install active-model-adapter

To include it we need to rewrite our serializer:

`import { ActiveModelSerializer } from 'active-model-adapter';`

ApplicationSerializer = ActiveModelSerializer.extend()

`export default ApplicationSerializer;`

and adapter:

`import ActiveModelAdapter from 'active-model-adapter'`

ApplicationAdapter = ActiveModelAdapter.extend
  namespace: 'api'

`export default ApplicationAdapter`

Sending the POST action to my backend with these change had the correct parameters and we are good to continue on our way.

Comments