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