any other id column pass in response of postman
1
account.rb in serializer folder
2
attribute :role do |object|
object&.role&.name
end
3
at the time of create approvers account_id and role_id will given and by default in response of approvers the name of role and user will show because i add this code in the serializer ::
attribute :role do |object|
object&.role&.name
end
...........................................................
full code ::
module AccountBlock
class AccountSerializer < BuilderBase::BaseSerializer
attributes *[
:activated,
:country_code,
:email,
:first_name,
:full_phone_number,
:last_name,
:phone_number,
:type,
:created_at,
:updated_at,
:device_id,
:unique_auth_id,
:custom_id
]
attribute :country_code do |object|
country_code_for object
end
attribute :phone_number do |object|
phone_number_for object
end
attribute :role do |object|
object&.role&.name
end
class << self
private
def country_code_for(object)
return nil unless Phonelib.valid?(object.full_phone_number)
Phonelib.parse(object.full_phone_number).country_code
end
def phone_number_for(object)
return nil unless Phonelib.valid?(object.full_phone_number)
Phonelib.parse(object.full_phone_number).raw_national
end
end
end
end
Comments
Post a Comment