lib/paginate/helper.rb in paginate-0.1.3 vs lib/paginate/helper.rb in paginate-1.0.0
- old
+ new
@@ -30,37 +30,39 @@
options.merge!(:url => args.first) if args.any?
Paginate::Renderer.new(options).render
end
- # In order to iterate the correct items you have to skip the latest collection's item.
- # We added this helper to automatically skip the latest item only if there's a next page,
- # which means that we have an extra item.
+ # In order to iterate the correct items you have to skip the last collection's item.
+ # We added this helper to automatically skip the last item only if there's a next page.
#
# <% iterate @items do |item| %>
# <% end %>
#
# If you want to grab the iteration index as well just expect it as a block parameter.
#
# <% iterate @items do |item, i|
# <% end %>
#
- #
# If you set a custom size while fetching items from database, you need to inform it while iterating.
#
# @items = Item.paginate(:page => 1, :size => 5)
#
# Then in your view:
#
# <% iterate @items, :size => 5 do |item| %>
# <% end %>
#
+ # You can receive the iteration counter by expecting two arguments.
+ #
+ # <% iterate @items do |item, i| do %>
+ # <% end %>
+ #
def iterate(collection, options = {}, &block)
options.reverse_merge!(:size => Paginate::Config.size)
- block_arity = block.arity
collection[0, options[:size]].each_with_index do |item, i|
- if block_arity == 1
+ if block.arity == 1
yield item
else
yield item, i
end
end