Will Paginate :分页不可或缺的插件

转载地址: http://iceskysl.1sters.com/?action=show&id=42

Rails以前的版本中包含了一个分页的方法,我使用的使用做了一些扩充,一直用到现在,看到很多人介绍Will Paginate,偶也不感兴趣,后来发现一个消息说Rails2.0将祛除内置的Paginate,于是就看看这个Will Paginate。

参考资料:

http://dev.rubyonrails.org/changeset/6993
http://errtheblog.com/post/4791
http://agilewebdevelopment.com/plugins/will_paginate
http://mattrobinson.net/2007/6/26/rails-plugins-scope_out-and-will_paginate
http://www.dcmanges.com/blog/21
http://www.lycom.de/past/2007/7/12/rails_will_paginate20070712_200741/
http://www.iteye.com/topic/108118
http://railscasts.com/episodes/51
附录:基本步骤和过程

安装will_paginate
ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate  
在Model中使用will_paginate
# models/product.rb    
def self.search(search, page)    
  paginate :per_page => 5, :page => page,    
           :conditions => ['name like ?', "%#{search}%"],    
           : order => 'name'    
end    
在controller中使用search
# products_controller.rb    
def index    
  @products = Product.search(params[:search], params[:page])    
end    
在页面中使用will_paginate
# <!-- products/index.rhtml -->    
 <%= will_paginate @products %>    

你可能感兴趣的:(.net,SVN,Blog,Ruby,Rails)