Will_paginate is very well designed plug-in. Besides Active-record object integration, it can integrate with array and any collection that you may have. Paginate an Array using will paginate..
Add this as method,
Array.class_eval do
def paginate(page=1, per_page=15)
pagination_array = WillPaginate::Collection.new(page, per_page, self.size)
start_index = pagination_array.offset
end_index = start_index + (per_page - 1)
array_to_concat = self[start_index..end_index]
array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat)
end
end
And with the array @results do @results.paginate
And with the array @results do @results.paginate
reference: http://www.devchix.com/2007/07/23/will_paginate-array/
Add this as method,
Array.class_eval do
def paginate(page=1, per_page=15)
pagination_array = WillPaginate::Collection.new(page, per_page, self.size)
start_index = pagination_array.offset
end_index = start_index + (per_page - 1)
array_to_concat = self[start_index..end_index]
array_to_concat.nil? ? [] : pagination_array.concat(array_to_concat)
end
end
And with the array @results do @results.paginate
And with the array @results do @results.paginate
reference: http://www.devchix.com/2007/07/23/will_paginate-array/
No comments:
Post a Comment