As I understand it, what he wants to do is not really pagination. Pagination
is users?page=1 but what he wants is to be at user/10 and when he clicks
next, it goes to user/11, when previous, user/9.

--Lasse

2010/2/15 EvanC <[email protected]>

> 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 <[email protected]> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to