Skip to content

Instantly share code, notes, and snippets.

@ubermajestix
Created October 7, 2008 20:37
Show Gist options
  • Save ubermajestix/15376 to your computer and use it in GitHub Desktop.
Save ubermajestix/15376 to your computer and use it in GitHub Desktop.
def tyler_paginate(collection, opts={} )
#next / prev / pages
page_count = WillPaginate::ViewHelpers.total_pages_for_collection(collection)
pagination_method = collection.first.class.to_s.downcase + "_pagination"
start = ((collection.current_page-1) * collection.per_page ) + 1
last = (start + collection.per_page - 1) > collection.total_entries ? collection.total_entries : (start + collection.per_page - 1)
header = "#{start} - #{last} of #{collection.total_entries}"
if collection.total_entries > collection.per_page
if page_count > 1
if collection.offset != 0
opts[:url][:page] = collection.previous_page
previous_link = "<a style=\"cursor:pointer; font-size:12px\" onclick=\"#{remote_function opts}\"> < previous </a>"
end
unless collection.current_page + 1 > page_count
opts[:url][:page] = collection.next_page
next_link = "<a style=\"cursor:pointer; font-size:12px\" onclick=\"#{remote_function opts}\"> next > </a>"
end
end
end
"<span style=\"font-size:12px\">#{previous_link.to_s||="" } #{header.to_s} #{next_link.to_s||=""} </span>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment