class Screenshot < ActiveRecord::Base belongs_to :package, :inverse_of=>:screenshots default_scope { order('uploaddatetime DESC') } def image_url(size) "#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png" end # Get the URL leading to a screenshot of this package def url(size) if self.approved # TODO: Make the path configurable basepath = "/screenshots/" else # TODO: Choose a path that makes unapproved screenshots unavailable basepath = "/screenshots/unapproved/" end File.join(basepath, self.package.name[0], self.package.name, "#{self.id}_#{size}.png") end # Return caption for full-screen screenshots. # Takes the description of a screenshot if available. # Otherwise it falls back to the general description of its package. def caption if self.description != '' self.description else self.package.description end end end