Rails 3 和 will_paginate - 优雅的方式,如何获得 total_pages [英] Rails 3 and will_paginate - elegant way, how to get total_pages

查看:27
本文介绍了Rails 3 和 will_paginate - 优雅的方式,如何获得 total_pages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Rails 3 中使用 will_paginate 插件,并且我正在尝试获取一些变量,即页面数 (total_pages).

I am working with will_paginate plugin in Rails 3 and I am trying to get to some variable the count of pages (total_pages).

我认为总页数在全局变量 @total_pages 中,或者在 @option[:total_pages]** 中,但是如果我在我看来使用这个变量,那么它不起作用.

I thought the total pages is in globally variable @total_pages, or in @option[:total_pages]**, but if I will use this variables in my view, so it don't work.

我知道,我可以通过这个插件分别获取我的项目在数据库表中的总页数,但不能那么优雅,如果我已经通过插件将该值存储在某个变量中...

I know, I can get the total pages of my items in DB table separately by this plugin, but couldn't be so elegant, if I will have that value already stored in some variable by plugin...

所以我想问你 - 以任何方式存在,如何获得这个值抛出 will_paginate 插件?

So I would like to ask you - exist any way, how to get this value throw will_paginate plugin?

推荐答案

如果您有帖子模型,

 <%= @posts.total_pages %>

将为您提供页面总数,即您需要引用您正在调用 will_paginate 的模型

will give you the pages total, i.e you need to reference the model you're calling will_paginate on

http://rdoc.info/github/mislav/will_paginate/master/将分页/集合

这篇关于Rails 3 和 will_paginate - 优雅的方式,如何获得 total_pages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆