Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created May 9, 2010 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrooijen/395189 to your computer and use it in GitHub Desktop.
Save mrrooijen/395189 to your computer and use it in GitHub Desktop.
def paginate(collection, controller, action)
return if collection.empty?
if collection.total_pages > collection.per_page
html = 1.upto(collection.total_pages).map { |i|
options = { :page => i }
options.merge!(:q => params[:q]) if params[:q].present?
link_to(i, url(controller, action, options), :class => [(params[:page].to_i == i ? :current : :page), ' link'])
}.join
content_tag(:div, html, :class => "pagination")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment