Sha256: b1c49929a26402597941d7a001e3b4a7664f394a167190b208fcaee92c63e331

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

class Upload < Asset
  
  default_scope where(:type => "Upload") if table_exists?
  
  validate :no_attachement_errors
  
  has_attached_file :attachment,
    :styles => Proc.new{ |clip| clip.instance.attachment_sizes },
    :default_style => :medium
    
  def image_content?
    attachment_content_type.match(/\/(jpeg|png|gif|tiff|x-photoshop)/)
  end
     
  def attachment_sizes
    if image_content?
      { :mini => '48x48>', :small => '150x150>', :medium => '420x300>', :large => '800x500>' }
    else
      {}
    end
  end
  
  def no_attachement_errors
    if attachment_file_name.blank? || !attachment.errors.empty?
      # uncomment this to get rid of the less-than-useful interrim messages
      errors.clear
      errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
      false
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_essentials-0.3.3 app/models/upload.rb
spree_essentials-0.3.2 app/models/upload.rb