I think you're missing one thing here. This precise construction means
that there is a significant chance that some items will never be seen at
all. If the first "page" is random, it's not "random within the
parameters of what would otherwise land on page 1", it's "random across
the entire database". And then you move to page 2, where it's created_at
What I would do is have a separate route for "random tease of what's in
the database", and then have a real "everything, in order" route as is
normal for an index + pagination.
Thanks Walter, it would certainly miss some of the items, but what you
are saying to have separate route for random and for pagination is may
be possible but right now i do not understand how to implement this, but
i will try to do it and if u can elaborate it further with example then
it would be helpful for me.
@foos = Foo.order('RAND()').limit(20) #mysql
#@foos = Foo.order('RANDOM()').limit(20) #sqlite
resources :foos do
<h1>Hey look at all the cool foos we have!</h1>
<%= render @foos %>
<p><%= foo.name %></p>
<p><%= foo.rank %></p>
<p><%= foo.serial_number %></p>
And then your index.html.erb would be exactly the same as it currently is, with the pagination and whatnot, and your index (controller) method would also be the same, with no worries about making the pagination smarter. Wherever you wanted your random sample to appear, you would simply use the sample method. And your index would be a normal index without any notion of randomness, so any possible foo could be shown or found.