Is there any way to customize will_paginate control button to add more button like FIRST and LAST, not only previous and next buttons. Thank you.
The first page is pretty easy:
link_to 'First Page', :action => :whatever, :page => 1
The last page a little tricky, in your model class add:
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
now you can do:
link_to 'Last page', :action => :whatever, :page => Model.last_page_number
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With