panko_serializer icon indicating copy to clipboard operation
panko_serializer copied to clipboard

Rendering serializers with additional parameters

Open railsfactory-selva opened this issue 4 years ago • 2 comments

AMS has facility to pass additional parameters to serializer i.e, render json: user, include_token: true, current_user_id: user.id

It would be nice if we have similar feature to add additional parameters on Panko for both single object serializer and array serializers,

render json: Panko::UserSerializer.new.serialize_to_json(user) render json: Panko::ArraySerializer.new(users, each_serializer: Panko::UserSerializer)

Currently it just accepts 1 parameters to be passed on

Tried using, render json: Panko::Response.new(       current_user_id: user.id,       include_token: true,       user: Panko::UserSerializer.new.serialize_to_json(user) )

But it's returning null response, and doesn't seem to be working.
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Panko::Response.

railsfactory-selva avatar Sep 18 '19 11:09 railsfactory-selva

@railsfactory-selva According to documentation you can pass hash of data with context parameter. https://yosiat.github.io/panko_serializer/attributes.html#method-attributes

irondnb avatar Dec 20 '19 09:12 irondnb

@railsfactory-selva is @irondnb answers your question?

yosiat avatar Jan 11 '20 11:01 yosiat