Rails 3 和 will_paginate - 优雅的方式,如何获取total_pages
我正在 Rails 3 中使用 will_paginate 插件,我试图获取一些变量的页数(total_pages)。
我认为总页数位于全局变量 @total_pages 中,或位于 @option[:total_pages]** 中,但如果我在我的视图中使用此变量,那么它不起作用。
我知道,我可以通过这个插件单独获取数据库表中项目的总页数,但不能这么优雅,如果我将该值已经通过插件存储在某个变量中......
所以我想问你 - 以任何方式存在,如何通过 will_paginate 插件获得这个值?
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).
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...
So I would like to ask you - exist any way, how to get this value throw will_paginate plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个帖子模型,
将为您提供总页数,即您需要引用您在
http://rdoc.info/github/mislav/will_paginate/master/WillPaginate/Collection
if you have a posts model,
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/WillPaginate/Collection