有没有办法自定义 will_paginate 控制按钮,添加更多的按钮,例如首个和最后一个按钮,而不仅仅是上一页和下一页按钮。谢谢。
link_to 'First Page', :action => :whatever, :page => 1
class << self
# number of records per page, from the will_paginate docs
def per_page
20
end
# takes a hash of finder conditions and returns a page number
# returns 1 if nothing was found, as not to break pagination by passing page=0
def last_page_number(conditions=nil)
total = count :all, :conditions => conditions
[((total - 1) / per_page) + 1, 1].max
end
end
现在你可以做:
link_to 'Last page', :action => :whatever, :page => Model.last_page_number
假设你正在对@users进行分页,那么将以下链接放入你的视图中
<%= link_to 'First Page', :action => 'index', :page => 1 %>
<%= will_paginate @users %>
<%= link_to 'Last Page', :action => 'index', :page => @users.page_count %>