Skip to content

Instantly share code, notes, and snippets.

@timgauthier
Created April 25, 2014 14:07
Show Gist options
  • Save timgauthier/11290823 to your computer and use it in GitHub Desktop.
Save timgauthier/11290823 to your computer and use it in GitHub Desktop.
I need to flip the direction, so that the next button takes you to the next newest and the previous takes you to the previous oldest page.
<% (page_number - num_pages .. page_number + num_pages).select{|i| i > 0 && i <= num_pages}.each do |i| %>
<% if i == page_number %>
<li>
<span class="active">
<%= i %>
</span>
</li>
<% else %>
<li>
<% page = nil %>
<% (i .. page_number).each do page = page ? page.metadata[:locals]['prev_page'] : prev_page; end %>
<% (page_number ... i).each do page = page ? page.metadata[:locals]['next_page'] : next_page; end %>
<%= link_to "#{i}", page && page.url %>
</li>
<% end %>
<% end %>
<% if paginate %>
<% if next_page %>
<li><%= link_to 'Next page <i class="fa fa-angle-right"></i>', next_page %></li>
<% else %>
<li>
<span class="disabled">Last Page <i class="fa fa-angle-right"></i></span>
</li>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment