Rails宝典之第五十一式: will_paginate

Edge Rails(将为Rails 2.0)中将内建的pagination移出作为插件classic_pagination
在本视频中推荐直接使用will_paginate插件,因为它更简单更容易

安装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 %>

你可能感兴趣的:(SVN,Google,网络应用,Ruby,Rails)