0,安装
可以安装为gem 或者plugin形式
1,效率
@words = SearchWord.paginate(:conditions => ["alphabet = ? ", char], :order=>"number desc",:page => params[:page] , :per_page=>100) @words = SearchWord.find(:all,:conditions=>["alphabet = ? ",char],:order=>'number desc').paginate(:page=>params[page],:per_page=>100)
上面两句分页查询的代码看似一样大,其实差别很大,第二个的效率低于第一个,生成的sql是分别是这样的:
ELECT * FROM `search_words` WHERE (alphabet = 101 ) ORDER BY number DESC SELECT * FROM `search_words` WHERE (alphabet = 101 ) ORDER BY number DESC limit 0,100
2,显示全部页数
效果 :
http://www.lightinthebox.com/producttags/B/
<% @words.total_pages.times do | page | %> <a href="/search/<%= word + '/' + page.to_s %>" ><%= page %></a> <% end %>
3 ,配置共用一个样式
enviroment.rb 中添加
require 'will_paginate' WillPaginate::ViewHelpers.pagination_options[:class] = 'digg_pagination' WillPaginate::ViewHelpers.pagination_options[:previous_label] = '<<' WillPaginate::ViewHelpers.pagination_options[:next_label] = '>>'
4,临时指定一个样式
<%= will_paginate @comments , :class => 'apple_paginate' , :previous_label => '<<上一页', :next_label => '下一页>>' , :renderer => 'WillPaginate::LinkRenderer' %>
5,…