Class: Cms::Attachments::FilesystemStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/cms/attachments/attachment_serving.rb

Class Method Summary collapse

Class Method Details

.attachments_storage_locationObject


36
37
38
# File 'lib/cms/attachments/attachment_serving.rb', line 36

def self.attachments_storage_location
  Rails.configuration.cms.attachments.storage_directory
end

.send_attachment(attachment, controller) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cms/attachments/attachment_serving.rb', line 40

def self.send_attachment(attachment, controller)
  style = controller.params[:style]
  style = "original" unless style
  path_to_file = attachment.path(style)
  if File.exists?(path_to_file)
    Rails.logger.debug "Sending file #{path_to_file}"
    controller.send_file(path_to_file,
                         :filename => attachment.file_name,
                         :type => attachment.file_type,
                         :disposition => "inline"
    )
  else
    msg = "Couldn't find file #{path_to_file}'"
    Rails.logger.error msg
    raise ActiveRecord::RecordNotFound.new(msg)
  end
end