Class: PhotoUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
app/uploaders/photo_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:



19
20
21
22
23
24
25
# File 'app/uploaders/photo_uploader.rb', line 19

def default_url
  # For Rails 3.1+ asset pipeline compatibility:
  # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))

  #{}"/images/fallback/" + [version_name, "default.png"].compact.join('_')
  'default_photo.png' #rails will look at 'app/assets/images/default_avatar.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/photo_uploader.rb', line 50

def extension_white_list
  %w(jpg jpeg gif png)
end

#store_dirObject

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



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

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