我使用 will_paginate 来获取分页中的值。考虑这个例子
if params[:page] || params[:per_page]
@users = User.paginate(:page => params[:page], :per_page
=> params[:per_page]).all(:order => 'id ASC')
else
@users = User.all(:order => 'id ASC')
end
format.json {
render json:
{:users => @users, :current_page => @users.current_page,
:total_pages => @users.total_pages,
:total_entries => @users.total_entries
}
}
如果我没有发送任何参数( params[:page] or params[:per_page] )
,那么它会显示
NoMethodError (undefined method `current_page' for #<Array:0x000002345ab655>)