Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable root in active model serializers

I'm using active model serializers(0.10.2) with :json adapter because in two serializers I need meta tag(meta tag is not included in :attributes adapter), I have few more serializers where I don't want root, is it possible to disable root per serializer?

Is it possible to use :json adapter in active model serializers v 0.10.2 and disable root?

like image 998
user525717 Avatar asked Nov 26 '22 03:11

user525717


1 Answers

I couldn't find a way to disable the root key when using the :json adapter. But, it sounds like you want to have some controller methods return meta data and other controller methods NOT return meta data, so you could use the default adapter (attributes) for methods with no meta data and then just declare the :json adapter on the controller methods where you need the meta data.

So, something like:

render json: articles, meta: articles_meta_method(articles), adapter: :json

of course articles_meta_method would have to be defined somewhere.

There's an example of using a meta method for pagination here

like image 143
Terry Ray Avatar answered Dec 08 '22 12:12

Terry Ray