ruby-on-rails – 如何分页Rabl的收藏
发布时间:2020-12-16 19:43:31 所属栏目:百科 来源:网络整理
导读:我有这个模板: # app/views/posts/index.rablcollection @posts = :postsattributes :id,:title,:subjectchild(:user) { attributes :full_name }node(:read) { |post| post.read_by?(@user) } 女巫返回: { "posts": [ { "post": { "id": 5,"title": "..."
我有这个模板:
# 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,"read": true } } ],"total": 42,"total_pages": 12 } 有任何想法吗?非常感谢! 解决方法
对于我的noob问题,对话是由README回答的.以下是分页的一个例子:
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进行分页. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |