paginating_find plug-in part 2
How to add “next page” and “previous page” links using the paginating_find plug-in.If you haven’t read the first part, read it if you want to know how to set up paginating_find
So far our view code for generating the links to different pages looks like this
<%= paginating_links(@posts) %>
To add the next and and previous page links we need to add these lines
<%= link_to 'previous page', :action => 'index', :page => @posts.previous_page %>
<%= link_to 'next page', :action => 'index', :page => @posts.next_page %>
Now that will work but when we are on the first page the “previous page” link will still be there, and when we are on the last page the “next page” link will be there, which we don’t want for obvious reasons. So how do we solve that problem?
Well we use the next_page? or previous_page? method to find out if a next or previous page exists, if it does then display the relevant link otherwise don’t display it, EASY!
<% if @posts.previous_page? %>
<%= link_to 'previous page', :action => 'index', :page => @posts.previous_page %>
<% end %>
<% if @posts.next_page? %>
<%= link_to 'previous page', :action => 'index', :page => @posts.next_page %>
<% end %>



August 11th, 2008 at 10:02 pm
Hi,
Can I use this plugin for find_by_sql query?