ruby-on-rails - Rails 3- Will_Paginate - 使分页链接更像 GMAIL

标签 ruby-on-rails ruby-on-rails-3 will-paginate

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

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

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

1 - 100 of 25409 较旧的 › 最旧的 »

<较新 101 - 200/25409 较旧 › 最旧 »

«最新 ←​​ 较新 25401 - 25409 共 25409

谢谢

最佳答案

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

“旧版”基本上是“下一页”,因此您可以在渲染器中重写 next_page 方法。 “最旧的”是“最后一页”;您需要添加一个方法,然后确保它包含在 pagination 方法返回的数组中(will_paginate 中内置的 total_pages 方法将在这里提供帮助)。

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

看看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 的最新设计在这方面非常出色。

关于ruby-on-rails - Rails 3- Will_Paginate - 使分页链接更像 GMAIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3896945/

相关文章:

ruby-on-rails - 在 will_paginate 中使用自定义名称

ruby-on-rails - Rails Kaminari - 如何对数组进行排序/分页?

ruby-on-rails - 如何根据 Parse REST API 中的 session token 检索用户?

javascript - js.erb 和 css.erb 文件上良好的代码突出显示、语法分析和代码辅助编辑器

ruby-on-rails - 在模型的属性名称中包含 "ID"

ruby-on-rails - 无法激活 rack (~> 1.4.0, runtime) 已经激活 rack-1.5.0

ruby-on-rails - Ruby:在字符串中搜索多个搜索词

ruby-on-rails - rails : Displaying published post by all and unpublished post of current_user

javascript - 仅在一页上运行 Javascript

javascript - 使用 will_paginate 更新 ajax 内容