A
A
Alexander Petrov2017-10-03 18:03:34
Ruby on Rails
Alexander Petrov, 2017-10-03 18:03:34

How to display data randomly?

Suppose I display some data
data=Data.all
. I will display data sorted by ID. And how to display all the data randomly? And so that every time everything is randomized?
If anything, I use kaminari, so making a random array for the array will not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Bordenyuk, 2017-10-03
@Mirkom63

Use the capabilities of your DBMS.
MySQL PostgreSQL
Data.order('RANDOM()').all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question