So, my application has photos belonging to the collections. I want to be able to display 13 photos from a specific collection on a page.
I tried this:
c = Collection.first @photos = c.photos.offset(rand(c.photos.count)).limit(13)
It works, sort of. The problem is that if the collection does not have more than 13 photos, then it does not necessarily return 13 photos. I need to specifically receive exactly 13 photos.
FWIW. In the case of my application, the collection is created only by administrators / mods, so we can ensure that the collection does not have at least 13 photos. I need to be able to make the selection of photos random when more than 13 are available.
How can i do this?
Andrew
source share