渲染FastJsonApi gem serialized_json的默认结果如下:
render json: FlashcardSerializer.new(flashcards).serialized_json
会是这样的:
{
"data": [
{
"id": "1",
"type": "flashcard",
"attributes": {
"question": "why?",
"answer": "pretty good",
"slug": null
}
},
{
"id": "2",
"type": "flashcard",
"attributes": {
"question": "What is 0",
"answer": "it is 0",
"slug": null
}
}
]
}
我宁愿添加一些额外的信息,特别是对于分页,我希望结果是这样的:
{
"data": [
{
"id": "1",
"type": "flashcard",
"attributes": {
"question": "why?",
"answer": "pretty good",
"slug": null
}
},
{
"id": "2",
"type": "flashcard",
"attributes": {
"question": "What is 0",
"answer": "it is 0",
"slug": null
}
},
"count":100,
"page":1,
]
}
我知道在 API 中管理分页的其他可用 gem,并且我知道如何在没有 Fastjson 的情况下做到这一点。这里的主要问题是,是否有任何方法可以从这个 gem 中获得上述结果,而无需对代码进行大量更改。谢谢