will_paginate:如何构建“下一页”链接?

时间:2011-05-25 08:15:15

标签: ruby-on-rails will-paginate

我知道这一定非常简单,但环顾四周后我找不到答案。

我正在使用will_paginate插件,我希望有一个简单的“下一页”链接,而不是整个will_paginate链接集。

我该怎么做?

谢谢!

3 个答案:

答案 0 :(得分:3)

这将为您提供一个简单的下一个按钮。

protected

# Tells WP how to render the "Next Page" link
  def next_page
    # The only difference from the default here is we renamed the link to "More"
    # and added a custom class, twitter_pagination
    previous_or_next_page(@collection.next_page, "Next", 'twitter_pagination') if @collection.next_page
  end

  # Remove all links except our :next_page
  def pagination
    [ :next_page ]
  end

告诉我们您是如何继续前进的。这是一个很棒的Blog Posts你也应该阅读。让我们知道您的身体情况如何。一切顺利。

答案 1 :(得分:2)

它实际上比你想象的要多得多,有些人可能称之为“Rails Way”。 http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate

但您也可以帮助我们使用方法current_pagetotal_pages。如下所示:

<% if @post.current_page < @post.total_pages %>
   <%= link_to "Next", "#{posts_path(@post)}?page=#{@post.current_page+1}" %>
<% end %>

答案 2 :(得分:1)

在Rails v4上使用will_paginate v3:

<%= will_paginate @posts, :page_links=>false %>