diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 7bfa65c..7e8e4e7 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -36,9 +36,13 @@ class GalleriesController < ApplicationController params = OrbitHelper.params images = [] - + total_images = 0 if !albums.blank? - while images.count < 9 and images.count < AlbumImage.count + albums.each do |album| + total_images = total_images + album.album_images.count + end + total_images = total_images > 9 ? 9 : total_images + while images.count < total_images and images.count < AlbumImage.count albums.each do |album| img = album.album_images.sample if !images.include?(img) && img != nil