Class: AvatarUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::RMagick
Defined in:
app/uploaders/avatar_uploader.rb

Instance Method Summary collapse

Instance Method Details

#default_urlObject

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



30
31
32
33
34
# File 'app/uploaders/avatar_uploader.rb', line 30

def default_url
  # For Rails 3.1+ asset pipeline compatibility:
  # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  "/images/default.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:



50
51
52
# File 'app/uploaders/avatar_uploader.rb', line 50

def extension_white_list
  %w(jpg jpeg gif png)
end

#move_to_cacheObject



25
26
27
# File 'app/uploaders/avatar_uploader.rb', line 25

def move_to_cache
  false
end

#scale(width, height) ⇒ Object



39
40
41
# File 'app/uploaders/avatar_uploader.rb', line 39

def scale(width, height)
  resize_to_limit(width, height)
end

#store_dirObject

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:



21
22
23
# File 'app/uploaders/avatar_uploader.rb', line 21

def store_dir
  "avatars/#{model.id}"
end