Paginator in Rails
paginator 绝对是任何web app必备之物,rails 1.1.6 内建的paginator很好用,很傻瓜,但是貌似它的处理方式也确实很傻,有很多感觉不爽的地方。有一个find plugin可以完成paginator的活,但是在我的系统上没跑起来,也没研究直接换Bruce的paginator gem,用起来还算顺手。View上面的表现需要自己完成,找到了一个方法,修改一下与paginator gem整合起来,跑的不错。
windowed_pagination_links这个helper让我改成了下面的样子:
- def windowed_pagination_links(pagingEnum, pager, options)
- link_to_current_page = options[:link_to_current_page]
- always_show_anchors = options[:always_show_anchors]
- padding = options[:window_size]
- current_page = pagingEnum.number
- html = ''
- #Calculate the window start and end pages
- padding = padding < 0 ? 0 : padding
- first = current_page-padding<1 ? 1 : current_page-padding
- last = current_page+padding>pager.number_of_pages ? pager.number_of_pages : current_page+padding
- # Print start page if anchors are enabled
- html << yield(1) if always_show_anchors and not first == 1
- # Print window pages
- first.upto(last) do |page|
- (current_page == page && !link_to_current_page) ? html << page : html << yield(page)
- end
- # Print end page if anchors are enabled
- html << yield(pager.number_of_pages) if always_show_anchors and not last == pager.number_of_pages
- html
- end
June 22nd, 2007 at 4:29 pm
谢谢你热心地上传了很多有用的MAXTHON插件,但是 WEB DOCUMENT PACKAGER以前在 2.0版本以下很好使用的,我也一直在用,现在升级了版本以后(我用的傲游(Maxthon)2.0 版 本 RC3(2.0.2.1360),这个插件就无法运行了。