README.txt in paginator-1.0.3 vs README.txt in paginator-1.0.4
- old
+ new
@@ -13,18 +13,23 @@
have to provide it with the total number of objects and a way to pull a specific
set of objects based on the offset and number of objects per page.
== SYNOPSIS:
+In both of these examples I'm using a PER_PAGE constant (the number of items per page), but it's merely for labeling purposes.
+
+You could, of course, just pass in the number of items per page directly to the initializer without assigning it somewhere beforehand.
+
=== In a Rails Application
- # In your controller
- PER_PAGE = 20
- @pager = ::Paginator.new(Foo.count, PER_PAGE) do |offset, per_page|
- Foo.find(:all, :limit => per_page, :offset => offset)
+ def index
+ @pager = ::Paginator.new(Foo.count, PER_PAGE) do |offset, per_page|
+ Foo.find(:all, :limit => per_page, :offset => offset)
+ end
+ @page = @pager.page(params[:page])
+ # respond_to here if you want it
end
- @page = @pager.page(params[:page])
# In your view
<% @page.items.each do |foo| %>
<%# Show something for each item %>
<% end %>
@@ -33,10 +38,9 @@
<%= link_to("Next", foos_url(:page => @page.next.number)) if @page.next? %>
=== Anything else
bunch_o_data = (1..60).to_a
- PER_PAGE = 10
pager = Paginator.new(bunch_o_data.size, PER_PAGE) do |offset, per_page|
bunch_o_data[offset,per_page]
end
pager.each do |page|
puts "Page ##{page.number}"