attachment_uploader.rb 572 字节
Newer Older
G
gitlabhq 已提交
1 2 3 4 5 6 7 8 9
# encoding: utf-8

class AttachmentUploader < CarrierWave::Uploader::Base
  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

10
  def image?
11 12 13 14 15 16 17 18 19 20
    img_ext = %w(png jpg jpeg)
    if file.respond_to?(:extension)
      img_ext.include?(file.extension)
    else
      # Not all CarrierWave storages respond to :extension
      ext = file.path.split('.').last
      img_ext.include?(ext)
    end
  rescue
    false
21
  end
22 23 24 25

  def secure_url
    "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
  end
G
gitlabhq 已提交
26
end