Skip to content

Instantly share code, notes, and snippets.

@spree
Created March 5, 2009 22:48
Show Gist options
  • Save spree/74613 to your computer and use it in GitHub Desktop.
Save spree/74613 to your computer and use it in GitHub Desktop.
<!-- Code by Ilya Grigorik - http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/ -->
<% if collection.page_count != collection.first_page -%>
<div class="pagination">
<ul>
<% if collection.previous_page? -%>
<li class="nextpage">
<%= link_to "&#171; #{t('previous')}", { :p => collection.previous_page }.merge(options) %>
</li>
<% else -%>
<li class="disablepage">&#171; <%= t('previous') %></li>
<% end -%>
<% last_page = 0 -%>
<% windowed_pagination_links(collection, :window_size => 2, :link_to_current_page => true, :always_show_anchors => true) do |n| -%>
<% if collection.page == n -%>
<li class="currentpage"><%= n %></li>
<% else -%>
<li><%= "..." if last_page+1 < n %>
<%= link_to n, {:id => params[:id], :p => n}.merge(options) %>
</li>
<% end -%>
<% last_page = n -%>
<% end -%>
<% if collection.next_page? -%>
<li class="nextpage">
<%= link_to "#{t('next')} &#187;", { :p => collection.next_page }.merge(options) %>
</li>
<% else -%>
<li class="disablepage">&#171; <%= t('next') %></li>
<% end -%>
</ul>
</div>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment