Just as the title says, how should I sort the api using the attribute in Active Model Serializer in Rails?
I have an example api consist of shopping list. It consist product name, location, and price. In my Serializer
class ShoppingListSerializer < ActiveModel::Serializer
attributes :id, :name, :location, :price
def id
Product.find(object.product_id).id
end
def name
Product.find(object.product_id).name
end
def location
Product.find(object.product_id).location
end
def price
Product.find(object.product_id).price
end
end
I want to sort it using the attribute name. How should I do that? Thank you.