Hi Bigos, You aren't using the view helper will_paginate gives you. It's as simple as:
@people = Person.paginate :page => params[:page] And in your view: <%= will_paginate @posts %> This will automatically generate the 'Previous' and 'Next' links. For further questions there is a dedicated will_paginate group at http://groups.google.com/group/will_paginate -- they'll be able to help you better! -- Evan On Feb 15, 2:53 pm, Bigos <ruby.obj...@googlemail.com> wrote: > 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.