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}"unlesslimit.nil?
Tag.find_by_sql(query)
end
protected
##
# Sets the Author marker for ownership on creation.
#
defset_author_id
self.author_id||=Application.current_author_id
end
##
# Checks to make sure that the file exists and is an image.
#
defvalidate_image_sanity
ifself.file[:tempfile].nil?
self.errors.add(:file,'File is not a file')
end
ifself.file[:content_type]!~/image\/\w+/
self.errors.add(:file,'File is not a supported type')
end
ifself.file[:size]>3*1048576
self.errors.add(:file,'File is too big (3MB max)')