我有这个模板:
# 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/