Project

General

Profile

Download (1.21 KB) Statistics
| Branch: | Tag: | Revision:
class ArtworkStepImage < ArtworkStep
has_many :artwork_step_thumbnails, :foreign_key => 'parent_id'

has_attachment :content_type => :image,
:max_size => MyCyma::Config.instance.max_uploaded_image_size_mb.megabyte,
:storage => :file_system,
:path_prefix => base_upload_path(),
:thumbnails => MyCyma::Config.instance.thumbnail_param_list,
:thumbnail_class => ArtworkStepThumbnail

validates_presence_of :filename, :date, :artwork_id #, :void
validates_uniqueness_of :filename, :scope => :artwork_id
validates_numericality_of :position, :only_integer => true, :greater_than_or_equal_to => 0
validates_as_attachment

public :after_process_attachment
attr_accessor :saved_attachment

def thumbnail(size)
return self if size.nil?

thumb = self.artwork_step_thumbnails.find_by_thumbnail(size.to_s)
if thumb.nil?
regen_thumbnail(size)
else
thumb
end
end

def regen_thumbnail(size_name)
return unless self.exists?
return if size_name.nil?

size = attachment_options[:thumbnails][size_name]
temp_file = create_temp_file
create_or_update_thumbnail(temp_file, size_name, size)
end

def exists?
File.exists?(self.full_filename)
end
end
(9-9/13)