Combining Multiple Serializers for one response. #360
-
|
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 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.
Replies: 1 comment 3 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.
You can use
paramswhere you can passuserobject.You can also use inheritance since it's just Ruby!