That's one reason I really like Bruce William's Paginator gem (
http://paginator.rubyforge.org/): it just paginates anything you give
it.
def index
@departments = Department.find(:all)
@categories = Category.find_all_by_department_id(params[:id])
@department = Department.find_by_department_id(params[:id])
product_count=
Product.find(:select=>'id', :conditions=>["on_department_promotion
= ?",true]
@pager = ::Paginator.new(product_count.length, 6) do |offset,
per_page|
Product.find(:all,:limit => per_page, :offset =>
offset, :conditions=>["on_department_promotion = ?",true])
end
@page = @
pager.page(params[:page])
end
# In your view
<% @page.each do |product| %>
<%# Show something for each item %>
<% end %>
<%= @page.number %>
<%= link_to("Prev", products_url(:page => @page.prev.number)) if
@page.prev? %>
<%= link_to("Next", products_url(:page => @page.next.number)) if
@page.next? %>
Or something like that: I just munged his example code with your
problem statement.
Ron