How to sort the answer Rails Active Model serializers

Oddly enough, I did not find anything about this ...

How can I sort my Rails JSON server? I am currently using Serializer ActiveModel:

embed :ids, include: true attributes :id, :name has_many :places 

I would like to sort inline places .

The only answer I found was this SO question , but it explains how the default serializer sort is, not how to sort.

+8
ruby-on-rails active-model-serializers
source share
1 answer

You can define it as a property and a descriptor sort. For example:

 def places object.places.order("title") end 

https://github.com/rails-api/active_model_serializers#associations

+19
source share

All Articles