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 %>

Methods

Constants

DEFAULT_OPTIONS = { :name => :page, :window_size => 2, :always_show_anchors => true, :link_to_current_page => false, :params => {}

Public Instance methods

Creates a basic HTML link bar for the given paginator. html_options are passed to link_to.

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

[Source]

    # File vendor/rails/actionpack/lib/action_view/helpers/pagination_helper.rb, line 37
37:       def pagination_links(paginator, options={}, html_options={})
38:         name = options[:name] || DEFAULT_OPTIONS[:name]
39:         params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
40:         
41:         pagination_links_each(paginator, options) do |n|
42:           params[name] = n
43:           link_to(n.to_s, params, html_options)
44:         end
45:       end

Iterate through the pages of a given paginator, invoking a block for each page number that needs to be rendered as a link.

[Source]

    # File vendor/rails/actionpack/lib/action_view/helpers/pagination_helper.rb, line 49
49:       def pagination_links_each(paginator, options)
50:         options = DEFAULT_OPTIONS.merge(options)
51:         link_to_current_page = options[:link_to_current_page]
52:         always_show_anchors = options[:always_show_anchors]
53: 
54:         current_page = paginator.current_page
55:         window_pages = current_page.window(options[:window_size]).pages
56:         return if window_pages.length <= 1 unless link_to_current_page
57:         
58:         first, last = paginator.first, paginator.last
59:         
60:         html = ''
61:         if always_show_anchors and not (wp_first = window_pages[0]).first?
62:           html << yield(first.number)
63:           html << ' ... ' if wp_first.number - first.number > 1
64:           html << ' '
65:         end
66:           
67:         window_pages.each do |page|
68:           if current_page == page && !link_to_current_page
69:             html << page.number.to_s
70:           else
71:             html << yield(page.number)
72:           end
73:           html << ' '
74:         end
75:         
76:         if always_show_anchors and not (wp_last = window_pages[-1]).last? 
77:           html << ' ... ' if last.number - wp_last.number > 1
78:           html << yield(last.number)
79:         end
80:         
81:         html
82:       end

[Validate]