Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3-将分页-使分页链接更像GMAIL_Ruby On Rails_Ruby On Rails 3_Will Paginate - Fatal编程技术网

Ruby on rails Rails 3-将分页-使分页链接更像GMAIL

Ruby on rails Rails 3-将分页-使分页链接更像GMAIL,ruby-on-rails,ruby-on-rails-3,will-paginate,Ruby On Rails,Ruby On Rails 3,Will Paginate,我正在使用Rails 3插件Will_Paginate,并使用以下教程学习如何自定义分页链接: 我的问题是,如何使分页链接更像GMAIL,例如: 25409名年长者中的1-100名›最年长者» 媫更新的101-200个,其中25409个较老›最老» «最新的è更新的25401-25409/25409 谢谢看起来该链接(几乎)包含了您需要的所有信息 “Older”基本上是“Next Page”,因此可以覆盖渲染器中的Next\u Page方法。 “最老”是“最后一页”;您需要添加一个方法,然后确

我正在使用Rails 3插件Will_Paginate,并使用以下教程学习如何自定义分页链接:

我的问题是,如何使分页链接更像GMAIL,例如:

25409名年长者中的1-100名›最年长者»

媫更新的101-200个,其中25409个较老›最老»

«最新的è更新的25401-25409/25409


谢谢

看起来该链接(几乎)包含了您需要的所有信息

“Older”基本上是“Next Page”,因此可以覆盖渲染器中的
Next\u Page
方法。 “最老”是“最后一页”;您需要添加一个方法,然后确保它包含在
pagination
方法返回的数组中(这里内置的
total_pages
方法将有所帮助)

然后对较新/最新版本执行相反的操作

看一看这些文件。它们具有您将覆盖的方法

我编写了一个自定义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
模块推文分页
类LinkRenderer
为了做到这一点,我需要知道的一切都可以通过阅读我上面链接的两个源文件来解决

我真的很惊讶这是多么容易做到;will_paginate的最新设计在这方面非常出色。

试试类似的设计

<%= will_paginate @items, :class => 'apple_pagination' %>
苹果分页“%”
类也可以是digg_分页、.flickr_分页


在此之前,您需要将pagination.css复制到公共/样式表中。

谢谢,这很酷。但我仍然不明白如何使它有条件(只有当它处于活动状态时才会显示更多内容)。。。另外,如何在链接(25406的1-100个)之前显示记录查看和计数请注意
if@collection.next_page
conditional-如果确实有下一页,它只显示“More”。至于项目编号,这有点复杂。查一下档案。它基本上是一个带有额外方法的数组,因此您可以调用
@collection.size
来了解此组中的项目数;将其乘以当前页面,以获得开始,将组中的项目数添加到开始,以获得最大限制,等等。作为后续行动,昨天我发布了一个Gem,旨在为will\u paginate提供不同的预构建渲染器,其中一个是Gmail。结果再次证明它非常简单(甚至比编写更难测试)。