mysql - Fetching a random record -


i developing ruby on rails question bank application.i want know how retrive random records database out duplication.and using mysql database.also random records show in view.

solution: 1

user.limit(10).order("rand()")

solution: 2

ids = user.pluck(:id).shuffle[0..9]
user.where(id: ids)


Comments

Popular posts from this blog

google app engine - 403 Forbidden POST - Flask WTForms -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -