It is very simple to implement will_paginate with Rails API application. We just have to pass page number and per page item. Per page item can be static also.
@posts = Post.paginate :page => params[:page]
render :json => {
:current_page => @posts.current_page,
:per_page => @posts.per_page,
:total_entries => @posts.total_entries,
:total_pages => @posts.total_pages,
:entries => @posts
}
No comments:
Post a Comment