ActiveModel::Serializers with DataMapper
Now that Steve Klabnik has released ActiveModel::Serializers version 0.7.0, and Ryan Bates has produced a fantastic Railscast on its usage (episode 409), I'd like to share how I'm using ActiveModel::Serializers with DataMapper to build an API for Ember.js with ember-data.
I love ActiveModel::Serializers and I love DataMapper. With a little work, they are a match made in heaven! Thankfully, the integration of the two is actually very easy, once you get down into it.
The biggest change was a commit I added to ActiveModel::Serializers to make eager loading work properly in DataMapper. Steve has already released this as a gem, so be sure to use a version >= 0.7.0.
Otherwise we just include the right support modules. I've chose to do this in an initializer in Rails called simply 'serializer.rb'.
Now you should be able to create Serializers to your heart's content and everything from DataMapper should work just like we want it. Thank you Steve and Ryan!
I'll followup with a blog on how I'm using ActiveModel::Serizliers to build APIs to work with well with ember-data and Ember.js.