will_paginate:如何构建“下一页”关联?

发布于 2024-11-09 11:05:42 字数 131 浏览 6 评论 0原文

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

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

我该怎么做?

谢谢!

I know this must be REALLY simple but after looking around I cannot find the answer.

I'm using the will_paginate plugin and I like to have a simple "next page" link instead of the whole will_paginate link collection.

How can I do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

神经大条 2024-11-16 11:05:43

在 Rails v4 上使用 will_paginate v3:

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

Using will_paginate v3 on Rails v4:

<%= will_paginate @posts, :page_links=>false %>
梦里泪两行 2024-11-16 11:05:42

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

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

让我们知道您的进展如何。这是一个很棒的 博客文章 您也应该阅读。让我们知道您的进展如何。一切顺利。

This will give you just a simple next button to work with.

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

Let us know how you get on. Here is a great Blog Posts you should read as well. Let us know how you get on. All the best.

稀香 2024-11-16 11:05:42

实际上,它比您想象的要复杂一些,有些人可能称之为“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 %>

It actually is a little more involved than you'd think to do it how some might call the "Rails Way". http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate

But you can also just make a helper and use the methods current_page and total_pages. So something like:

<% if @post.current_page < @post.total_pages %>
   <%= link_to "Next", "#{posts_path(@post)}?page=#{@post.current_page+1}" %>
<% end %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文