滑轨版本:6.0.0 Ruby版本:2.6.3
render json: AreaSerializer.new(
Area.all, paginate(pagy), params: { current_user: current_user }
), status: ok
attributes :nodes do |area, params|
...
end
错误:
ArgumentError (wrong number of arguments (given 3, expected 1..2)):
答案 0 :(得分:1)
我尝试了另一种方法,它正在起作用,
在控制器中
areas = Area.all
options = {
links: paginate(pagy),
params: { current_user: @current_user }
}
render json: AreaSerializer.new(areas, options),
status: ok
在序列化器中
attributes :nodes do |area, params|
area.users.where.not(id: params[:current_user].id)
end
并且link键会在Serializer中自动呈现。
{
data: [
{},
{} // areas hash
],
links: {
first: "",
last: "",
}
}
答案 1 :(得分:0)
使用类似这样的内容:
render json: AreaSerializer.new(
Area.all,
{ params: { paginate: paginate(pagy), current_user: @current_user } }
), status: ok
序列化器
attributes :nodes do |area, params|
...
params[:current_user]
params[:paginate]
...
end