I’m using Rails 4 and a PostGres database. For a particular table, I want to serve a bunch of table records to a user, but in a randomized order. Further, I don’t want to display all the data at once, but rather would prefer the user page through it. So if the randomized order for all the data has IDs
10, 8, 6, 4, 2, 9, 7, 5, 3, 1
I would want the data with IDs
10, 8, 6, 4, 2
to be displayed on page 1 and the data with ids 9, 7, 5, 3, 1 to be displayed on page 2 (assuming each page has five results). How do I write a finder method that will randomize the data in such a way or how do I take the results of a finder method and randomize their ordering? Note that the initial group of records won’t be everything in the table (it will be everything with the enabled field set to true).
Aucun commentaire:
Enregistrer un commentaire