will_paginate 从 1 开始下一页计数,并带有索引 [英] will_paginate starts next page count from 1 with indexing
本文介绍了will_paginate 从 1 开始下一页计数,并带有索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个帖子索引页面,它是这样的:
I have an indexed page of posts and it goes like:
<% @posts.each_with_index do |post, index| %>
//do some rendering
<% end %>
<%= will_paginate @posts %>
在我的控制器中,我有以下内容:
While in my controller i have the following:
def index
@posts = Post.paginate(:page => params[:page], :per_page => 15)
end
第一页编号最多为 15,但当我进入第二页时,索引计数回到 1.我希望它从 15 开始.谢谢x
The first page numbering counts up to 15 but when i proceed to page two the index count goes back to 1. I want it to proceed from 15 onwards. Thankx
推荐答案
不得不浏览 will_paginate 代码才能找到解决方案.在配方模型中,我添加了此方法.
Had to browse through the will_paginate code to come up with a solution. In recipe model i added this method.
def offset(page)
per_page = 15
@off_set = WillPaginate::PageNumber(page).to_offset(per_page).to_i
end
在我的控制器中,我添加了:
While in my controller i added:
def index
@page = params[:page]
end
最后在我看来我添加了这个:
Finally in my view i added this:
<%= index + recipe.offset(@page) + 1 %>
这篇关于will_paginate 从 1 开始下一页计数,并带有索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文