mercredi 25 mars 2020

Method name Alias in serializable hash

Need to pass on filtered data without changing the name of the field in response using serializable hash. A User entity which is related to Class. User uses serializable_hash as:

def serializable_hash(options={})
super(:only => [:id, :email, :phone, :first_name, :last_name],
      :include => [:classes ]  
end

Where I want to filter classes based on active status. Like :methods => [:types , :active_classes]) but this particular field to be shown as classes not active_classes in the response like:

{"id": ...,
 "email": ....,
 "classes": [] 
}

Aucun commentaire:

Enregistrer un commentaire