Rails version : 6.0.0 Ruby version : 2.6.3
render json: AreaSerializer.new(
Area.all, paginate(pagy), params: { current_user: current_user }
), status: ok
attributes :nodes do |area, params|
...
end
Error:
ArgumentError (wrong number of arguments (given 3, expected 1..2)):
I tried another way and it was working,
In Controller
areas = Area.all
options = {
links: paginate(pagy),
params: { current_user: @current_user }
}
render json: AreaSerializer.new(areas, options),
status: ok
In serializer
attributes :nodes do |area, params|
area.users.where.not(id: params[:current_user].id)
end
And the links key is rendering automatically in Serializer.
{
data: [
{},
{} // areas hash
],
links: {
first: "",
last: "",
}
}