Last Updated: February 25, 2016
·
3.321K
· macfanatic

ActiveModel::Serializers - JSON API Heaven

I've used Rabl & Jbuildler (my favorite so far) as well as overriding good old to_json on my models to craft JSON responses for API's for quite awhile now. I thought that Jbuilder might be the best that it got, with a nice DSL for use in the view layer, and partials.

Today, I want to introduce you to Active Model Serializers. Essentially follows the decorator pattern for transforming your model instances into JSON.

Very clean, and the best part? I also use Inherited Resources and this integrates into all my InheritedResources responses without any effort or having to define view files.

Here's a sample of all the pieces playing well together: https://gist.github.com/4280164

4 Responses
Add your response

FYI your Gist link is busted

over 1 year ago ·

broken gist link

over 1 year ago ·

Found his Github Gists; nothing relating to ActiveModel::Serializers. Must have been taken down for some reason, Matt?

over 1 year ago ·

Must have removed it at some point, sorry everyone!

over 1 year ago ·