Sha256: 7a5cda76921685cb5aa5a3611cf9a0a94d711c3ed3bec658b84ede1de1914c91

Contents?: true

Size: 899 Bytes

Versions: 9

Compression:

Stored size: 899 Bytes

Contents

module Alchemy
  class AttachmentsController < BaseController
    before_action :load_attachment
    authorize_resource class: Alchemy::Attachment

    # sends file inline. i.e. for viewing pdfs/movies in browser
    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

    # sends file as attachment. aka download
    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

    private

    def load_attachment
      @attachment = Attachment.find(params[:id])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.6 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.5 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.4 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.3 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.2 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.1 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-4.0.0.beta app/controllers/alchemy/attachments_controller.rb
alchemy_cms-3.6.0 app/controllers/alchemy/attachments_controller.rb