0
votes

Is there a way to scope this endpoint (User#Show) on my Rails API, maybe in the serializer? I want to return only the user's last delivery_address, not all of them. I don't want it to effect non API requests.

def show @user = User.find(params[:id]) respond_with @user, include: ['delivery_addresses'] end

I have tried things like 'delivery_address.last', but that doesn't work and I can't find an explanation on the AMS repo...

1

1 Answers

1
votes

In your serializer specify attribute :last_delivery and add the method def last_delivery; object.delivery_addresses.last; end if I understand your question