I have a Persons table created with scaffold. I was trying to flick
between records by clicking on Previous and Next links. I was
struggling to understand will_paginate, and finally came up with
following solution, and I'm wondering if it could be done better.
Would it be better to have one query to a database returning previous
current and next record instead having two?

@person_previous = Person.paginate :all, :page => params[:page],
  :order => 'id DESC', :per_page => 1, :conditions => "id <
#{params[:id]}"
@person_next = Person.paginate :all, :page => params[:page],
  :order => 'id ASC', :per_page => 1, :conditions => "id >
#{params[:id]}"

<% @person_previous.each do |el|%>
<%= link_to 'Previous', el %>
<% end %>

<% @person_next.each do |el|%>
<%= link_to 'Next', el %>
<% end %>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to