http://rock.errtheblog.com/will_paginate
PagingEnumerator 想要一次只取10筆的分頁作法
PagingEnumerator 自己去new
==controller==
@items = NewsItem.find_all_news(order, 10, params[:page])
==model==
def self.find_all_news(order, size, page)
offset = ((page.to_i.nonzero? || 1) -1 ) * size
total = NewsItem.count
total = total > 10000 ? 10000 : total
news = NewsItem.find(:all, :order => order, :limit => size, :offset => offset)
PagingEnumerator.new(size, total, false, page, 1) do news end
end
沒有留言:
張貼留言