use the pagination_links.
@customer_pages, @customers = paginate(:customers, options_hash)
then in your view you have access to @customer_pages which is a
paginator, and therefore can do things like this:
<% paginator = @customer_pages %>
<%= unless paginator.current == paginator.first then link_to
("first", :page => paginator.first)
else ''first'' end %>
<%= if paginator.current.previous then link_to("prev", :page =>
paginator.current.previous)
else ''prev'' end %>
<%= if paginator.current.next then link_to("next", :page =>
paginator.current.next)
else ''next'' end %>
<%= unless paginator.current == paginator.last then link_to
("last", :page => paginator.last)
else ''last'' end %>
| <%= pagination_links @customer_pages, {:window_size => 5} %>
It gets even more fun if you''re passing a hash of values for
conditions (like search filtering, or pop-up-value filtering... then
you need to build an options hash, too... and you end up like this:
<% # options hash for pagination links
opt_hash = { :search_box => @search_box }
opt_hash[:is_something] = @is_something unless(@is_something.empty?)
# etc...
%>
<% params_hash = opt_hash # grab the params hash before the :page key
of it has been set - for the pagination links down below %>
<%= unless paginator.current == paginator.first then
opt_hash[:page] = paginator.first
link_to("first", opt_hash)
else ''first'' end %>
<%= if paginator.current.previous then
opt_hash[:page] = paginator.current.previous
link_to("prev", opt_hash)
else ''prev'' end %>
<%= if paginator.current.next then
opt_hash[:page] = paginator.current.next
link_to("next", opt_hash)
else ''next'' end %>
<%= unless paginator.current == paginator.last then
opt_hash[:page] = paginator.last
link_to("last", opt_hash)
else ''last'' end %>
| <%= pagination_links @customer_pages, {:window_size => 5, :params
=> params_hash} %>
Julian.
On 01/04/2006, at 3:02 AM, szymek wrote:
> Hi!
>
> I''ve got a list of project on the main page and if one of them is
> selected i render a partial using ajax with data of selected project.
>
> How to create links to next/previous project using pagination?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails