From dec7581cecca935d998beb6e2aa09d0a2c49d72f Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Nov 2008 01:42:19 -0600 Subject: [PATCH] better finder --- app/models/photo.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 7b44db7..1131693 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -49,14 +49,12 @@ class Photo < ActiveRecord::Base # Finds a Photo that the requested user can vote on by checking it against # all of the photos previously voted. # - def self.next_available_votable_photo(user) + def self.next_available_votable_photo(user, include_facebook = false) pids = Vote.voted_photo_ids(user) - c = if pids.empty? - nil - else - "photos.id NOT IN (#{pids.join(',')})" - end - self.find :first, :conditions => c, :order => 'id ASC' + c = [] + c << "photos.id NOT IN (#{pids.join(',')})" unless pids.empty? + c << "photos.facebook_id IS NULL" unless include_facebook + self.find :first, :conditions => c.join(' AND '), :order => 'id ASC' end ##