Created
January 9, 2009 11:35
-
-
Save electronicbites/45089 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper method to paginate a non ActiveRecord collection like a Array | |
def paginate_collection(collection, opts = {}) | |
opts[:per_page] ||= 20 | |
opts[:page] ||= 1 | |
opts[:page] = opts[:page].to_i | |
opts[:per_page] = opts[:per_page].to_i | |
returning WillPaginate::Collection.new( opts[:page], opts[:per_page], collection.size ) do |pager| | |
start = (opts[:page]-1) * opts[:per_page] | |
finish = start + opts[:per_page] | |
pager.replace collection[ start...finish ] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment