gpt4 book ai didi

ruby-on-rails - 如何为 Rabl 的集合分页

转载 作者:行者123 更新时间:2023-12-04 00:42:40 24 4
gpt4 key购买 nike

我有这个模板:

# app/views/posts/index.rabl
collection @posts => :posts
attributes :id, :title, :subject
child(:user) { attributes :full_name }
node(:read) { |post| post.read_by?(@user) }

女巫归来:
{
"posts": [
{
"post": {
"id": 5,
"title": "...",
"subject": "...",
"user": {
"full_name": "..."
},
"read": true
}
}
]
}

我想添加一些分页参数以呈现这个:
{
"posts": [
{
"post": {
"id": 5,
"title": "...",
"subject": "...",
"user": {
"full_name": "..."
},
"read": true
}
}
],
"total": 42,
"total_pages": 12
}

有什么想法吗?非常感谢!

最佳答案

对不起,我的菜鸟问题,自述文件已经回答了。下面是一个分页示例:

object false

node(:total) {|m| @posts.total_count }
node(:total_pages) {|m| @posts.num_pages }

child(@posts) do
extends "api/v1/posts/show"
end

注意:我正在使用 Kaminari用于分页。

关于ruby-on-rails - 如何为 Rabl 的集合分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com