Commit 9959888f

mo k <mo@mokhan.ca>
2012-11-06 14:44:29
only show published photos on the home page.
1 parent d010146
Changed files (2)
app/models/creation.rb
@@ -40,4 +40,12 @@ class Creation < ActiveRecord::Base
     self.update_attribute(:is_published, true)
     self.save!
   end
+
+  def published?
+    photos.count > 0
+  end
+
+  def is_safe_for_children?
+    :is_published == false
+  end
 end
app/services/find_all_creations_query.rb
@@ -3,6 +3,16 @@ class FindAllCreationsQuery
     @user = user
   end
   def fetch(params)
-    Creation.where(:is_restricted => false, :is_published => true).page(params[:page]).per(16)
+    make_pageable(find_creations, params[:page])
+  end
+
+  private
+  def find_creations
+    Creation.all.select do |creation|
+      creation.published? && creation.is_safe_for_children?
+    end
+  end
+  def make_pageable(items, page)
+    Kaminari.paginate_array(items).page(page).per(16)
   end
 end