Replies: 1 comment 2 replies
-
I believe you can do this with: class ContactSerializer
include Alba::Serializer
attributes :id, :name
attributes :birthday, :home_address, if: proc { |contact| contact.has_permission? }
end |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have an app where a User has_many Contacts. On the front end we want to display a list of contacts however we don't want to leak sensitive information so we have two serializers. ContactsFullSerializer and ContactsLiteSerializer. What we want to do is get a list of contacts
@contacts = current_user.contacts
and then respond where if the user has permission to view a contact the response is is rendered with ContactFullSerializer and if the user does not have permission then it uses ContactLiteSerializer. This would give us json like this for a user that had permission for 1 of 3 contacts:Is there a clever way to do this with Alba? We could loop though the contacts manually and merge everything at the end but that seems ugly.
Beta Was this translation helpful? Give feedback.
All reactions