<< Back

How to specify a custom model class for your ActiveModel::Serializer 0.8 Serializer

Sep 11, 2014

ActiveModel::Serializers gives you a lot of flexibility and modularity when it come to generating JSON for your Rails api. Serializer just work when the serializer is named after the model it references ( MyModelNameSerializer). You also knew you could easily extend a base ActiveModelSerializer using class inheritance MyExtendedSerializer < MyModelSerializer. Recently, however, I found myself building a serializer that couldn't be named by ActiveModel::Serializer convention and couldn't inherit from the base serializer for that class.

So where does this gem find it's dependent class?

It turns out that the method Serializer#model_class, defined on Serializer defines this behavior. It was relatively simple to override this behavior: Just override this method in your serializer so that the class method model_class refers to the parent class.

Building your Tolerance for Risk

Mar 16, 2013

In the past year, I've quit my comfortable job, started my own consulting business, moved to another country (한국!), learned ruby on rails and started working on product at a startup. It's been a whirlwind of a year and I've learned a ton about taking...

Always test your app in IE8

Feb 21, 2013

I had a particularly stark reminder today of why it is still important to do cross-browser testing. While IE8 has now fallen below 25% market share, it still makes up a significant chunk of the traffic that hits our app each day. One simple bug in...

More >>