Class: AvatarUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- AvatarUploader
- Includes:
- CarrierWave::MimeTypes, CarrierWave::MiniMagick, DmCore::AccountHelper
- Defined in:
- app/uploaders/avatar_uploader.rb
Overview
Instance Method Summary collapse
-
#default_url ⇒ Object
Provide a default URL as a default if there hasn’t been a file uploaded: ——————————————————————————.
-
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
-
#filename ⇒ Object
——————————————————————————.
-
#resize_to_width(width) ⇒ Object
We basically want the width to be the max, allowing the height to grow ——————————————————————————.
-
#store_dir ⇒ Object
——————————————————————————.
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_url ⇒ Object
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_list ⇒ Object
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 |
#filename ⇒ Object
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_dir ⇒ Object
14 15 16 |
# File 'app/uploaders/avatar_uploader.rb', line 14 def store_dir "#{Rails.root}/public/site_assets/_shared/avatars" end |