Class: Alchemy::AttachmentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/alchemy/attachments_controller.rb

Instance Method Summary collapse

Methods included from Modules

included, #module_definition_for, register_module

Methods included from AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#downloadObject

sends file as attachment. aka download



22
23
24
25
26
27
28
29
30
# File 'app/controllers/alchemy/attachments_controller.rb', line 22

def download
  response.headers["Content-Length"] = @attachment.file.size.to_s
  send_file(
    @attachment.file.path, {
      filename: @attachment.file_name,
      type: @attachment.file_mime_type
    }
  )
end

#showObject

sends file inline. i.e. for viewing pdfs/movies in browser



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/alchemy/attachments_controller.rb', line 9

def show
  response.headers["Content-Length"] = @attachment.file.size.to_s
  send_file(
    @attachment.file.path,
    {
      filename: @attachment.file_name,
      type: @attachment.file_mime_type,
      disposition: "inline"
    }
  )
end