| Module | ActionView::Helpers::PaginationHelper |
| In: |
vendor/rails/actionpack/lib/action_view/helpers/pagination_helper.rb
|
Provides methods for linking to ActionController::Pagination objects.
You can also build your links manually, like in this example:
<%= link_to "Previous page", { :page => paginator.current.previous } if paginator.current.previous %>
<%= link_to "Next page", { :page => paginator.current.next } if paginator.current.next =%>
| DEFAULT_OPTIONS | = | { :name => :page, :window_size => 2, :always_show_anchors => true, :link_to_current_page => false, :params => {} |
Creates a basic HTML link bar for the given paginator.
options are:
| :name: | the routing name for this paginator (defaults to page) |
| :window_size: | the number of pages to show around the current page (defaults to +2+) |
| :always_show_anchors: | whether or not the first and last pages should always be shown (defaults to true) |
| :link_to_current_page: | whether or not the current page should be linked to (defaults to false) |
| :params: | any additional routing parameters for page URLs |
# File vendor/rails/actionpack/lib/action_view/helpers/pagination_helper.rb, line 36
36: def pagination_links(paginator, options={})
37: options.merge!(DEFAULT_OPTIONS) {|key, old, new| old}
38:
39: window_pages = paginator.current.window(options[:window_size]).pages
40:
41: return if window_pages.length <= 1 unless
42: options[:link_to_current_page]
43:
44: first, last = paginator.first, paginator.last
45:
46: returning html = '' do
47: if options[:always_show_anchors] and not window_pages[0].first?
48: html << link_to(first.number, { options[:name] => first }.update( options[:params] ))
49: html << ' ... ' if window_pages[0].number - first.number > 1
50: html << ' '
51: end
52:
53: window_pages.each do |page|
54: if paginator.current == page && !options[:link_to_current_page]
55: html << page.number.to_s
56: else
57: html << link_to(page.number, { options[:name] => page }.update( options[:params] ))
58: end
59: html << ' '
60: end
61:
62: if options[:always_show_anchors] && !window_pages.last.last?
63: html << ' ... ' if last.number - window_pages[-1].number > 1
64: html << link_to(paginator.last.number, { options[:name] => last }.update( options[:params]))
65: end
66: end
67: end