Class: PhotoUploader

Inherits:
BaseUploader
  • Object
show all
Defined in:
app/uploaders/photo_uploader.rb

Instance Method Summary collapse

Methods inherited from BaseUploader

#default_url, #extension_white_list, #store_dir

Instance Method Details

#filenameObject

Override the filename of the uploaded files:


5
6
7
8
9
10
11
12
# File 'app/uploaders/photo_uploader.rb', line 5

def filename
  if super.present?
    # current_path 是 Carrierwave 上传过程临时创建的一个文件,有时间标记,所以它将是唯一的
    # 此方法只使用 Ruby China 这类图片上传的场景
    @name ||= Digest::MD5.hexdigest(current_path)
    "#{Time.now.year}/#{@name}.#{file.extension.downcase}"
  end
end