I’m looking for a way to get a random database entry (Video) that has a category_id equal to one I provide.
The code I’m currently using to get random Videos,
def self.random()
@count = self.count()
self.find(:first, :offset => rand(count))
end
This code works perfectly for finding a random video, however I need to constrain it to a video that has the :category_id that I provide.
Any help would be appreciated.
It might be something like this
I’m a rails noob, so I don’t know, maybe there is a more efficient way to do this