Sha256: dea0a5ad04d6b36ddc8ae5789ca310bdb18217f76824f9c6567cd640d246c72c

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

class Image < Asset
  validate :no_attachement_errors
  has_attached_file :attachment, 
                    :styles => { :mini => '48x48>', :small => '100x100>', :product => '240x240>', :large => '600x600>' }, 
                    :default_style => :product,
                    :url => "/assets/products/:id/:style/:basename.:extension",
                    :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"

  # save the w,h of the original image (from which others can be calculated)
  # we need to look at the write-queue for images which have not been saved yet
  after_post_process :find_dimensions
  def find_dimensions
    temporary = attachment.queued_for_write[:original] 
    filename = temporary.path unless temporary.nil?
    filename = attachment.path if filename.blank?
    geometry = Paperclip::Geometry.from_file(filename)
    self.attachment_width  = geometry.width
    self.attachment_height = geometry.height
  end

  # if there are errors from the plugin, then add a more meaningful message
  def no_attachement_errors
    unless 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

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-0.30.2 app/models/image.rb
spree_core-0.40.4 app/models/image.rb
spree_core-0.40.3 app/models/image.rb
spree_core-0.40.2 app/models/image.rb
spree_core-0.40.1 app/models/image.rb
spree_core-0.40.0 app/models/image.rb
spree_core-0.30.1 app/models/image.rb
spree_core-0.30.0 app/models/image.rb
spree_core-0.30.0.beta1 app/models/image.rb