From c9218b951d56ae0a62a88e36cdf716070b336df8 Mon Sep 17 00:00:00 2001 From: Coleman Date: Fri, 27 Jun 2008 20:54:04 -0500 Subject: [PATCH] adding the ability to tell if the file exists --- app/models/photo.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/models/photo.rb b/app/models/photo.rb index cd29314..7dca0bc 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -22,6 +22,20 @@ class Photo < ActiveRecord::Base "#{Merb.root}/public/photos/#{id}" end + ## + # Checks to see if the file is found on the filesystem. + # + def exist? + File.exist?(self.pathname) + end + + ## + # Returns the full path to the file on the filesystem. + # + def pathname + "#{self.base_directory}/#{self.filename}" + end + def self.popular_tags(limit = nil) query = "SELECT tags.id, tags.name, count(*) AS count FROM photo_tags, tags, photos WHERE tags.id = tag_id AND photo_tags.photo_id = photos.id GROUP BY tags.id, tags.name ORDER BY tags.name ASC" query << " LIMIT #{limit}" unless limit.nil?