Class: FileUploader

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

Instance Method Summary collapse

Instance Method Details

#filenameObject


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

def filename
  "#{model.name}.#{file.extension}"
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:


10
11
12
# File 'app/uploaders/file_uploader.rb', line 10

def store_dir
  "uploads/attachments/#{partition_name(model.name)}"
end

#url(filename: nil) ⇒ String

Manipulate the 'response-content-disposition' header to support file name.

Parameters:

  • filename (String)

    The file name of the downloaded file.

Returns:

  • (String)

    The url with options.


22
23
24
25
26
27
# File 'app/uploaders/file_uploader.rb', line 22

def url(filename: nil)
  query_option = { 'response-content-disposition' => 'attachment;' }
  query_option['response-content-disposition'] += " filename=\"#{filename}\"" if filename

  super(query: query_option)
end