Rails 3 and will_paginate - elegant way, how to get total_pages

ぃ、小莉子 提交于 2020-01-02 02:01:48

问题


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?


回答1:


if you have a posts model,

 <%= @posts.total_pages %>

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



来源:https://stackoverflow.com/questions/6976274/rails-3-and-will-paginate-elegant-way-how-to-get-total-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!