诗歌rails之 will_paginate

安装will_paginate
svn:

svn://errtheblog.com/svn/plugins/will_paginate

git:

script/plugin install git://github.com/mislav/will_paginate.git

在Model中使用will_paginate

  1. # models/product.rb  
  2. def self.search(search, page)  
  3.   paginate :per_page => 5, :page => page,  
  4.            :conditions => ['name like ?'"%#{search}%"],  
  5.            : order => 'name'  
  6. end  
在controller中使用search
  1. # products_controller.rb  
  2. def index  
  3.   @products = Product.search(params[:search], params[:page])  
  4. end  
在页面中使用will_paginate
  1. <!-- products/index.rhtml -->  
  2. <%= will_paginate @products %> 
posted @ 2009-07-06 17:19  麦飞  阅读(320)  评论(0编辑  收藏  举报