Ruby Forum Ruby on Rails > Newbies: Read this before asking about pagination

Posted by Mike Garey (random52k)
on 12.07.2007 23:44
(Received via mailing list)
I've just read three* different messages on the list, all posted
within a day of each other, and all having problems with the same
thing - rails built in pagination.

The common misconception seems to be that rails built in pagination
works as follows:

# grab a list of all the females
@users = User.find(:all, :conditions => ['gender = ?', 'F'])

# paginate the list:
@user_pages, @users = paginate(:users, :per_page => 10)

The above will paginate a list of users, however, it will NOT have the
conditions applied to it that you specified in the first find
statement (grabbing a list of females).  The two statements are not
related to each other.  The first finds all the females and stores the
results in the @users instance variable.  The second finds and
paginates _ALL_ of the users and stores them in the @users ivar,
overwriting the original contents.  This is most likely _not_ what you
want.

If you wanted to paginate a list of all the females, the correct way
to do it is the following

# paginate a list of females
@user_pages, @users = paginate(:users, :conditions => ['gender = ?',
'F'], :per_page => 10)

now, having said that, please be aware that the rails built in
pagination has been deprecated! (see here for more details
http://dev.rubyonrails.org/changeset/6992)  In other words, do not use
it for future projects!

Instead, you should be using something like the will_paginate plugin
(you can read about it here: http://errtheblog.com/post/4791)

Hopefully this will help reduce some confusion..

Mike



* the messages I'm referring to..
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/92190b21dc5c08f5/f4849b96c2b5a943#f4849b96c2b5a943

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/63d0aee496998a99/a415d6df0fbb6957#a415d6df0fbb6957

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/fcb0000ac2959193/80bc69f22efdf44f#80bc69f22efdf44f
Posted by gene.tani@gmail.com (Guest)
on 13.07.2007 01:02
(Received via mailing list)
On Jul 12, 2:43 pm, "Mike Garey" <random...@gmail.com> wrote:
> # paginate the list:
>
>
>
> http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/...

good writeup, i think this would be worthwhile for the FAQ (assuming
the author wants to start building out the page:

http://www.faisal.com/docs/ror-list-faq.html
Posted by Chris Hall (au5lander)
on 13.07.2007 01:23
(Received via mailing list)
another great alternative is the paginator gem.

http://paginator.rubyforge.org/
Posted by Ron Mr. (rawn027)
on 13.07.2007 01:49
(Received via mailing list)
I am looking to setup a "test deployment" server for rails and I was
wondering everyone input on which is a good solution to work on.

According to litespeed using only their server with ruby-lsapi is the
ONLY way to go :-P

I would just like some realworld experience.

Thanks!
Posted by Ron Mr. (rawn027)
on 13.07.2007 03:16
(Received via mailing list)
I am looking to setup a "test deployment" server for rails and I was
wondering everyone input on which is a good solution to work on.

According to litespeed using only their server with ruby-lsapi is the
ONLY way to go :-P

I would just like some realworld experience.

Thanks!
Posted by Chris Hall (au5lander)
on 13.07.2007 03:36
(Received via mailing list)
we use apache + mongrel at work.  easy setup and we have never had a
problem.  no experience with litespeed.

good luck in your decision.
Posted by Ron Mr. (rawn027)
on 13.07.2007 03:55
(Received via mailing list)
Do you have any pointers on setting this up? I have a FreeBSD server
which I am quite fluent with. Not so much with apache or mongrel.

Regards,
Ron
Posted by Adrian Madrid (Guest)
on 13.07.2007 07:22
(Received via mailing list)
Ron,

I run multiple environments (apache + mongrels, apache + litespeed,
litespeed only) and I can't tell you nothing beats litespeed in how
easy it is to setup and how fast and stable it is. Recently I
benchmarked one of my apps both with mongrel, mongrel + evented and
litespeed and LS was not only faster but required less RAM. My mongrel
processes started at 33MB and grew into 60-70MB while the Ruby
processes under LS stayed at 33MB. And we are talking under sets of
100K requests on 5/10/50 concurrent requests. For me there is no
discussion now, LS all the way.

Hope it helps,


Adrian Madrid


On 7/12/07, Ronald Valente <rawn027@gmail.com> wrote:
> >
> >> According to litespeed using only their server with ruby-lsapi is the
>
>
> >
>


--
Adrian Esteban Madrid
Posted by Richard Hancock (Guest)
on 13.07.2007 14:10
(Received via mailing list)
How well did the Apache + Mongrel do?  I have a similar situation as the 
OP
but I have less options at this time to experiment with.  The only 2 I
really have right now is Apache + Mongrel or Apache + FCGI.

TIA,
Richard

On 7/13/07, Adrian Madrid <aemadrid@gmail.com> wrote:
> processes under LS stayed at 33MB. And we are talking under sets of
> >
> > > we use apache + mongrel at work.  easy setup and we have never had a
> > >> ONLY way to go :-P
> >
> > >
> >
>
>
> --
> Adrian Esteban Madrid
>
> >
>


--
Richard J Hancock
Developer/System Administrator
Posted by Philip Hallstrom (Guest)
on 13.07.2007 19:52
(Received via mailing list)
I can second litespeed.  It's pretty nice, just be sure to give the docs 
a
good read to understand their GUI and stuff.  It's not hard, but the 
docs
will help give you a good understanding of how it works.

One nice thing about litespeed is that it can spawn/kill off the lsapi
processes based on load.  Which is nice for my little server with lots 
of
rails apps, but very little traffic (ie, me and my family usually).

I've used mongrel too and it's very nice as well, but the ram is used 
all
the time regardless of whether or not you're getting any traffic.
Posted by snacktime (Guest)
on 13.07.2007 20:01
(Received via mailing list)
I was playing around with litespeed last night for the first time and
was impressed.  It's main advantage IMO over the typical http server
-> mongrel cluster -> rails setup is that it has fewer moving parts.
A mongrel setup typically has something like monit running also.

So far it's my favorite, and I've tried pretty much everything,
including jruby on rails and mongrels running under smf in solaris
behind a hardware load balancer (which is my second favorite).

Chris
Posted by Ron Mr. (rawn027)
on 13.07.2007 22:34
(Received via mailing list)
Defiantly do not do FCGI.

-Ron