@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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
First, yeah, never directly interpolate query parameters (or any user
input) into your SQL queries. Second, use the paginate method to only
fetch the records relevant for the current page, as the will_paginate
view helper takes care of the rest. Did you look at the documentation
(http://gitrdoc.com/mislav/will_paginate/tree/master/) for the
will_paginate method? It's designed to generate the Previous, Next, and
anything-in-between links for you...
ESSENTIALLY, you just wanna do this in your controller:
@people = Person.paginate, :per_page => 1, :page => params[:page],
:order => "id ASC"
and then in your view just
<%= will_paginate @people, :page_links => false %>
The gem does pretty much everything for you, just take the time to
understand the documentation and the examples, and read the source for
anything that's still doesn't make sense.
--
Posted via http://www.ruby-forum.com/.
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
Thats definitely still pagination. Shall we can leave it as an "exercise
for the reader" to use the more "resourceful" type links?
Now I know why I was getting urls like users?page2. I have learned a
lot over last few days, but please forgive me asking silly questions.
I still get confused, perhaps I'm trying to learn to much too soon.
Anyway, thank you all for the code examples, I will have a closer
look at them tomorrow, after having some sleep.
Thank you very much,
Jack
On 15 Feb, 22:04, Paul Harrington <li...@ruby-forum.com> wrote:
> Lasse Bunk wrote:
> > 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 <e...@cancelliere.ca>
in controller:
@jobseeker_previous = Jobseeker.find :all, :order => 'id
DESC', :conditions => ["id < ?",@jobseeker.id], :limit => 1
@jobseeker_next = Jobseeker.find :all, :order => 'id
ASC', :conditions => ["id > ?",@jobseeker.id], :limit => 1
in view:
<%@jobseeker_previous.each do |el|%>
<%= link_to 'Previous', el %>
<% end %>
<%@jobseeker_next.each do |el|%>
<%= link_to 'Next', el %>
<% end %>
I tried few solutions and this one, where I get a collection
containing one element, seems to be most convenient for handling first
and last record, and is more idiot proof than unnecessarily having to
test for nil object.