2012-12-06 40 views
0

我的帖子的索引页,它是这样:will_paginate从1开始下一个页面数与索引

<% @posts.each_with_index do |post, index| %> 
    //do some rendering 
<% end %> 
<%= will_paginate @posts %> 

虽然在我的控制,我有以下几点:

def index 
    @posts = Post.paginate(:page => params[:page], :per_page => 15) 
end 

第一页编号计数到15,但是当我进入第二页时,索引计数会回到1.我希望它从15开始。 Thankx

+0

什么'调试@ posts'节目吗?前15或下15?如果下一个15 - 那么你可以尝试'@ posts.to_a.each_with_index' – MikDiet

+0

让我试试看,看到 – capdiz

+0

@Mik_Die它失败了。仍在试图弄清楚 – capdiz

回答

0

不得不浏览will_paginate代码来提出解决方案。在配方模型中,我添加了这种方法。

def offset(page) 
    per_page = 15 
    @off_set = WillPaginate::PageNumber(page).to_offset(per_page).to_i 
end 

虽然在我的控制器我说:

def index 
    @page = params[:page] 
end 

最后,在我看来,我添加了这个:

<%= index + recipe.offset(@page) + 1 %> 
相关问题