原创作者: hideto   阅读:1181次   评论:1条   更新时间:2011-05-26    
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 %>
评论 共 1 条 请登录后发表评论
1 楼 refar 2011-01-07 13:00
能评论吗???

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics