Sha256: 318fe5c3815522f642ba06adbb266be04c6c4252e075863b88886219802afc7a

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 KB

Contents

class Image < Asset
  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 validate
    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

15 entries across 15 versions & 2 rubygems

Version Path
spree-0.11.4 app/models/image.rb
spree-0.11.3 app/models/image.rb
spree-0.11.2 app/models/image.rb
spree-0.11.1 app/models/image.rb
spree-0.11.0 app/models/image.rb
spree-0.10.2 app/models/image.rb
spree-0.10.1 app/models/image.rb
spree-0.10.0 app/models/image.rb
spree-0.10.0.beta app/models/image.rb
spree-enriquez-0.9.4 app/models/image.rb
spree-0.9.4 app/models/image.rb
spree-0.9.3 app/models/image.rb
spree-0.9.2 app/models/image.rb
spree-0.9.1 app/models/image.rb
spree-0.9.0 app/models/image.rb