Class: AvatarUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MimeTypes, CarrierWave::MiniMagick, DmCore::AccountHelper
Defined in:
app/uploaders/avatar_uploader.rb

Overview


Instance Method Summary collapse

Methods included from DmCore::AccountHelper

#account_prefix, #account_protected_assets, #account_site_assets, #account_site_assets_media, #account_site_assets_media_url, #account_site_assets_url, #current_account

Instance Method Details

#default_urlObject

Provide a default URL as a default if there hasn’t been a file uploaded:




63
64
65
# File 'app/uploaders/avatar_uploader.rb', line 63

def default_url
  "/site_assets/_shared/avatars/" + ["empty_avatar", version_name].compact.join('_') + '.png'
end

#extension_white_listObject

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:




57
58
59
# File 'app/uploaders/avatar_uploader.rb', line 57

def extension_white_list
  %w(jpg jpeg gif png)
end

#filenameObject




19
20
21
# File 'app/uploaders/avatar_uploader.rb', line 19

def filename
   "#{secure_token}.#{file.extension}" if original_filename.present?
end

#resize_to_width(width) ⇒ Object

We basically want the width to be the max, allowing the height to grow




25
26
27
28
29
30
31
# File 'app/uploaders/avatar_uploader.rb', line 25

def resize_to_width(width)
  manipulate! do |img|
    img.resize "#{width}>"
    img = yield(img) if block_given?
    img
  end
end

#store_dirObject




14
15
16
# File 'app/uploaders/avatar_uploader.rb', line 14

def store_dir
  "#{Rails.root}/public/site_assets/_shared/avatars"
end