之前用的是rails1.2.3 实现分页的方法是用paginate方法,在rails2.0.2中被去掉了,不可以使用....
而在rails 2.0.2中则用了will_paginate 插件,下载地址:
http://www.javaeye.com/topic/154713使用方法:
1,把下载的will_paginate拷贝到项目的vendor->plugins 目录下
2,controller中:
@messages = Message.paginate :page => params[:page],
:per_page => 8 :page 参数是will_paginate默认的,不是用户定义的,@message是定义的实例变量,Message是数据库里的表对象,:per_page是每页显示的条数
3,view中:
<%= will_paginate @messages, :prev_label => '上一页', :next_label => '下一页' %>
就这么简单,你的分页就实现了!
另外:添加传参 <%= will_paginate @items, :params=>{:flag=>'user'} %>
参数参考:
ref: http://gitrdoc.com/mislav/will_paginate/tree/master/ (API)
ref: http://groups.google.com/group/will_paginate/browse_thread/thread/e65fab5aa96c85ae
设置自己的样式:
http://www.blogjava.net/fl1429/archive/2009/03/25/261802.html
link:
http://bbs.railschina.com/thread-421-1-4.html
http://www.cnblogs.com/ayuan/archive/2008/03/12/1102001.html
posted on 2009-03-09 15:08
fl1429 阅读(805)
评论(0) 编辑 收藏 所属分类:
Rails