will_paginate JSON支持? [英] will_paginate JSON support?
本文介绍了will_paginate JSON支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怀疑是否有人可以告诉我,如果will_paginate可以支持JSON,或者必须被黑客入侵?
I wonder if anyone could please tell me if will_paginate can support JSON out of the box or if this has to be hacked?
我想添加页面数据到JSON响应,而will_paginate管理分页。
I would like to add page data to the JSON responses while will_paginate manages pagination.
推荐答案
Something in the lines of:
@posts = Post.paginate :page => params[:page]
respond_to do |format|
format.json {
render :json => {
:current_page => @posts.current_page,
:per_page => @posts.per_page,
:total_entries => @posts.total_entries,
:entries => @posts
}
}
end
你想要什么格式,你总是可以在WillPaginate :: Collection上定义一个 to_json
方法。
Once you figure out what format you want, you can always define a to_json
method on a WillPaginate::Collection.
这篇关于will_paginate JSON支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文