之前用的是rails1.2.3 實(shí)現(xiàn)分頁(yè)的方法是用paginate方法,在rails2.0.2中被去掉了,不可以使用....
而在rails 2.0.2中則用了will_paginate 插件,下載地址:
http://www.javaeye.com/topic/154713使用方法:
1,把下載的will_paginate拷貝到項(xiàng)目的vendor->plugins 目錄下
2,controller中:
@messages = Message.paginate :page => params[:page],
:per_page => 8:page 參數(shù)是will_paginate默認(rèn)的,不是用戶定義的,@message是定義的實(shí)例變量,Message是數(shù)據(jù)庫(kù)里的表對(duì)象,:per_page是每頁(yè)顯示的條數(shù)
3,view中:
<%= will_paginate @messages, :prev_label => '上一頁(yè)', :next_label => '下一頁(yè)' %>
就這么簡(jiǎn)單,你的分頁(yè)就實(shí)現(xiàn)了!
另外:添加傳參 <%= will_paginate @items, :params=>{:flag=>'user'} %>
參數(shù)參考:
ref: http://gitrdoc.com/mislav/will_paginate/tree/master/ (API)
ref: http://groups.google.com/group/will_paginate/browse_thread/thread/e65fab5aa96c85ae
設(shè)置自己的樣式:
http://m.tkk7.com/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 閱讀(809)
評(píng)論(0) 編輯 收藏 所屬分類:
Rails