Ruby on Rails - will_paginate:如何构建"next page"链接?



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

我使用的是will_page插件,我喜欢有一个简单的"下一页"链接,而不是整个will_page链接集合。

我该怎么做?

谢谢!

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

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

让我们知道你的进展。这里有一个伟大的博客文章,你也应该阅读。让我们知道你过得怎么样。祝你一切顺利。

实际上,它比你想象的要复杂一些——有些人可能会称之为"Rails之路"。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 %>

在Rails v4:上使用will_paginate v3

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