Rails API gem to accept Ember JSONAPIAdapter POST/PUTS

I’ve been using the Ember JSONAPIAdapter along with AMS (active_model_serializer) for Rails and have been extremely happy with the result (except for having to add a custom serializer for snake case).

However, when it comes time to POST or PUT the records to the server, Rails goes back to the old nested parameter style of deserializing, so I end up doing $.ajax then store.pushPayload to save and update all records.

Does anyone know of an active model deserializer like AMS for Rails that consume JSON API formatted data?

1 Like

There’s JSONAPI::Resources.

Just curious – any particular reason to use $.ajax with AMS as opposed to a custom serializer like here? Ember and Rails 5 with JSON API: A Modern Bridge - Ember Igniter

1 Like

I have spent days trying to get this exact scenario working, I have been using AMS but have been frustrated by the lack of side-loading support unless you use :json_api, which means that you have to accept JSON API in rails, which as far as I can tell is not easy, especially with related data.

The good news is that they are currently working on a deserialization feature in AMS which I am looking forward to, the current branch does not seem to work with JSON API though.

I am trying to get a custom serializer set up in my ember app based on the above comment (Thanks).

I really would have thought that this would come up quite often but I have really struggled to find a comprehensive guide on how to set up rails to work seamlessly with JSON API, (JSONAPI::Resources looks a little too restrictive for me, although that may just be inexperience talking)

1 Like

Perhaps it’s a little hacky, but I’ve just followed Rails conventions on the client side as a solution.

For example I have _form Ember templates to render the inputs with Rails-style parameter names (such as foo[field1] and foo[field2]) then I just called $.ajax with data = form.serializeArray(). Some degree of automation based on the Ember Data model would be nice, but this is okay for now.

@emberigniter Thanks for the link to the JSONAPI::Resources- however I’m building on top of existing ActiveRecord objects and a live database so I don’t think it would be a good fit for this project.

Your blog post looks interesting, however. I’ll need to take a closer look at that serializer when I have time.

1 Like