Sha256: d99d5c5dea1814a51ac10831d39f5c490138756f6f7dacb8502af98c685d859c

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class Upload < Asset
  
  default_scope where(:type => "Upload") if table_exists?
  
  validate :no_attachement_errors
  
  # Check for spree_heroku
  #   https://github.com/paxer/spree-heroku
  #
  if defined?(SpreeHeroku)
    has_attached_file :attachment,
      :styles => Proc.new{ |clip| clip.instance.attachment_sizes },
      :default_style => :medium,
      :path => "assets/uploads/:id/:style/:basename.:extension",
      :storage => "s3",
      :s3_credentials => "#{Rails.root}/config/s3.yml"
  else
    has_attached_file :attachment,
      :styles => Proc.new{ |clip| clip.instance.attachment_sizes },
      :default_style => :medium,
      :url => "/assets/uploads/:id/:style/:basename.:extension",
      :path => ":rails_root/public/assets/uploads/:id/:style/:basename.:extension"
  end
  
  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

1 entries across 1 versions & 1 rubygems

Version Path
spree_essentials-0.3.1 app/models/upload.rb