2

I'm using the Rails 3 plugin Will_Paginate and have been using the following tutorial to learn how to customize the pagination links:

http://thewebfellas.com/blog/2010/8/22/revisited-roll-your-own-pagination-links-with-will_paginate-and-rails-3/

My question is, how to make the pagination links more like GMAIL, example:

1 - 100 of 25409 Older › Oldest »

‹ Newer 101 - 200 of 25409 Older › Oldest »

« Newest ‹ Newer 25401 - 25409 of 25409

Thanks

4

2 回答 2

3

看起来该链接具有(几乎)您需要的所有信息。

“旧”基本上是“下一页”,因此您next_page在渲染器中覆盖该方法。“最旧”是“最后一页”;您需要添加一个方法,然后确保它包含在您的pagination方法返回的数组中(total_pageswill_paginate 内置的方法将在此处提供帮助)。

然后对 Newer/Newest 执行相反的操作。

查看link_renderer.rblink_renderer_base.rb文件。他们有你将要覆盖的方法。

我编写了一个自定义 will_paginate 3 渲染器来模拟 GitHub/Twitter 风格的“更多”分页。我已经注释了下面的代码。它不会让你准确地到达你需要去的地方,但它是一个开始。

module TwitterPagination
  class LinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
    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, "More", 'twitter_pagination') if @collection.next_page
    end

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

为了做到这一点,我需要知道的一切都可以通过阅读我上面链接的两个源文件来弄清楚。

这真的让我感到惊讶,这很容易做到。will_paginate 的最新设计在这方面非常出色。

于 2010-10-09T18:09:54.683 回答
0

尝试类似的东西

<%= will_paginate @items, :class => 'apple_pagination' %>

类也可以是 digg_pagination, .flickr_pagination 。

在此之前,您需要下载pagination.css 并将其复制到您的公共/样式表。

于 2011-12-19T20:55:44.053 回答