我使用了Rails 3插件Will_Paginate并已使用下面的教程来学习如何自定义分页链接:Rails的3- Will_Paginate - 让分页链接更像GMAIL
我的问题是,如何使分页链接更像GMAIL,例如:
1 - 100 25409旧版>最旧»
<更新的101 - 200 25409旧版>最旧»
«最新<较新的25401 - 25409的25409
感谢
我使用了Rails 3插件Will_Paginate并已使用下面的教程来学习如何自定义分页链接:Rails的3- Will_Paginate - 让分页链接更像GMAIL
我的问题是,如何使分页链接更像GMAIL,例如:
1 - 100 25409旧版>最旧»
<更新的101 - 200 25409旧版>最旧»
«最新<较新的25401 - 25409的25409
感谢
它看起来像该链接有(几乎)所有你需要的信息。
“较旧”基本上是“下一页”,因此您在渲染器中覆盖了next_page
方法。 “最旧”是“最后一页”;您需要添加一个方法,然后确保它包含在由pagination
方法返回的数组中(will_paginate中构建的total_pages
方法将在此处有所帮助)。
然后做相反的更新/最新。
看看link_renderer.rb和link_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的最新设计在这方面非常出色。
尝试像
<%= will_paginate @items, :class => 'apple_pagination' %>
类也可以digg_pagination,.flickr_pagination。
在此之前,您需要download并将pagination.css复制到您的公共/样式表中。
谢谢,这很酷。但我仍然没有遵循如何使它有条件(只有显示更多,如果它是活动的)...另外,如何让记录查看&计数显示在链接之前(25406的1 - 100) – AnApprentice 2010-10-09 18:30:06
请注意'if @ “collection.next_page”条件 - 如果实际上有下一页,它只显示“更多”。至于编号的项目,这有点复杂。查看[collection.rb]文件(http://github.com/mislav/will_paginate/blob/v3.0.pre2/lib/will_paginate/collection.rb)。它基本上是一个带有额外方法的数组,因此您可以调用'@ collection.size'来知道此组中的项目数量;乘以'current_page'获得开始,将组中的项目数加到开始以获得最大边界,等等。 – 2010-10-09 18:38:22
明白了 - 谢谢! – AnApprentice 2010-10-10 03:18:13