Module: Paginate::Helper
- Defined in:
- lib/paginate/helper.rb
Instance Method Summary collapse
-
#paginate(collection, *args) ⇒ Object
Display pagination based on the collection and current page.
-
#render(*args, &block) ⇒ Object
Override the original render method, so we can strip the additional item from the collection, without changing your workflow with the iterate “always felt dirty” method.
Instance Method Details
#paginate(collection, *args) ⇒ Object
Display pagination based on the collection and current page.
<%= paginate @posts %>
<%= paginate @posts, options %>
<%= paginate @posts, posts_path, options %>
The available options are:
-
:url
: the URL which page numbers will be appended to. Can be proc or string. -
:id
: the HTML id that will identify the pagination block. -
:size
: the page size. When not specified will default toPaginate.configuration.size
. -
:param_name
: the page param name. When not specified will default toPaginate.configuration.param_name
. -
:renderer
: A class that will be used to render the pagination. When not specified will default toPaginate::Renderer::List
.<%= paginate @posts, proc {|page| posts_path(page) } <%= paginate @posts, :url => proc {|page| posts_path(page) }
You don’t have to specify the URL; the current requested URI will be used if you don’t provide it.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/paginate/helper.rb', line 22 def paginate(collection, *args) = args. param_name = [ [:param_name], Paginate.configuration.param_name, :page ].compact.first renderer = [ [:renderer], Paginate.configuration.renderer, Paginate::Renderer::List ].compact.first .merge!({ collection: collection, page: params[param_name], param_name: param_name, fullpath: request.fullpath }) .merge!(url: args.first) if args.any? renderer.new(self, ).render end |
#render(*args, &block) ⇒ Object
Override the original render method, so we can strip the additional item from the collection, without changing your workflow with the iterate “always felt dirty” method.
To render a paginated set, just pass the :paginate => true
option. You can also provide a custom size with :size => number
<%= render @posts, :paginate => true %>
<%= render @pots, :paginate => true, :size => 20 %>
<%= render "post", :collection => @posts, :paginate => true, :size => 20 %>
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/paginate/helper.rb', line 59 def render(*args, &block) = args. paginated = .delete(:paginate) size = .delete(:size) { Paginate.configuration.size } return super(*[*args, ], &block) unless paginated collection = .delete(:collection) { args.shift } collection = collection[0, size] super(collection, *[*args, ], &block) end |