small medium large xlarge

10 Feb 2016, 13:52
Kai Groeteke (1 post)


I have a page where I want to show random records from the database. Problem is of course that the page is different every time, which does not help the performance.

I use the following method to get random entries: ~~~ def self.random self.limit(10).offset(rand(self.count)).first end ~~~

What is the best way to do this? Shall I create a view with random objects in the database? Can Rails handle it but in a smarter way?

Thanks for help!

You must be logged in to comment