Skip to content

Instantly share code, notes, and snippets.

@rick
Created August 12, 2008 21:43
Show Gist options
  • Save rick/5152 to your computer and use it in GitHub Desktop.
Save rick/5152 to your computer and use it in GitHub Desktop.
def paginator
if @pager.number_of_pages>1
p = "<div id='paginator'>"
p << link_to("1", {:page => 1}, :title => "Page 1")+" " if @pager.number_of_pages>7 and @page.number>4
p << "... " if @pager.number_of_pages>8 and @page.number>5
p << link_to(@page.number-6, {:page => @page.number-6}, :title => "Page " + (@page.number-6).to_s)+" " if @page.number>6 and @pager.number_of_pages<@page.number+1
p << link_to(@page.number-5, {:page => @page.number-5}, :title => "Page " + (@page.number-5).to_s)+" " if @page.number>5 and @pager.number_of_pages<@page.number+2
p << link_to(@page.number-4, {:page => @page.number-4}, :title => "Page " + (@page.number-4).to_s)+" " if @page.number>4 and @pager.number_of_pages<@page.number+3
p << link_to(@page.number-3, {:page => @page.number-3}, :title => "Page " + (@page.number-3).to_s)+" " if @page.number>3
p << link_to(@page.number-2, {:page => @page.number-2}, :title => "Page " + (@page.number-2).to_s)+" " if @page.number>2
p << link_to(@page.number-1, {:page => @page.number-1}, :title => "Page " + (@page.number-1).to_s)+" " if @page.prev?
p << "<span class='active_page'>" + @page.number.to_s + "</span> "
p << link_to(@page.number+1, {:page => @page.number+1}, :title => "Page " + (@page.number+1).to_s)+" " if @page.next?
p << link_to(@page.number+2, {:page => @page.number+2}, :title => "Page " + (@page.number+2).to_s)+" " if @pager.number_of_pages>[email protected]+2
p << link_to(@page.number+3, {:page => @page.number+3}, :title => "Page " + (@page.number+3).to_s)+" " if @pager.number_of_pages>[email protected]+3
p << link_to(@page.number+4, {:page => @page.number+4}, :title => "Page " + (@page.number+4).to_s)+" " if @pager.number_of_pages>[email protected]+4 and @page.number<=3
p << link_to(@page.number+5, {:page => @page.number+5}, :title => "Page " + (@page.number+5).to_s)+" " if @pager.number_of_pages>[email protected]+5 and @page.number<=2
p << link_to(@page.number+6, {:page => @page.number+6}, :title => "Page " + (@page.number+6).to_s)+" " if @pager.number_of_pages>[email protected]+6 and @page.number==1
p << "... " if @pager.number_of_pages>@page.number+4 and @pager.number_of_pages>8
p << link_to(@pager.number_of_pages, {:page => @pager.number_of_pages}, :title => "Page " + @pager.number_of_pages.to_s)+" " if @pager.number_of_pages>@page.number+3 and @pager.number_of_pages>7
p << "</div>"
p
else
""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment