Sha256: 7e0b6805e52420f548be97b2f4a8143731cdde099984965956924d8605a9558d

Contents?: true

Size: 930 Bytes

Versions: 56

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

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

56 entries across 56 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.6 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.9 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.4.1 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.4.0 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.5 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.8 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.1.13 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.0.16 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.4 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.3 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.2 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.7 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.1 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.3.0 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.6 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.5 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.1.12 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.0.15 app/controllers/alchemy/attachments_controller.rb
alchemy_cms-7.2.4 app/controllers/alchemy/attachments_controller.rb