Sha256: 1f71a0b58746f22caf4ad1bd6720b0c0fd37858b2432d1241884206b075f4bce

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

class SurveyImage < ActiveRecord::Base
    belongs_to :imageable, :polymorphic => true

    has_attached_file :photo, PAPERCLIP_STORAGE_OPTS ##  this constant is in /config/environments/*.rb

  #image_tag @product.photo.url(:small)
    validates_attachment_presence :photo
    validates_attachment_size     :photo, :less_than => 5.megabytes
    validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']

    validates :imageable_type,  :presence => true
    #validates :imageable_id,    :presence => true
    validate :validate_photo

    default_scope :order => 'position'

    # save the w,h of the original image (from which others can be calculated)
    MAIN_LOGO = 'logo'

    # if there are errors from the plugin, then add a more meaningful message
    def validate_photo
      unless photo.errors.empty?
        # uncomment this to get rid of the less-than-useful interrim messages
        # errors.clear
        errors.add :attachment, "Paperclip returned errors for file '#{photo_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
survey_says-0.0.2 app/models/survey_image.rb
survey_says-0.0.1 app/models/survey_image.rb