Sha256: a56599931b95ec4c7ccf214636a33f3f229ef3fdf42fb3e52d6444258d1e08f6
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Lcms module Engine class DownloadsController < Lcms::Engine::ApplicationController include AnalyticsTracking before_action :ga_track, except: %i(pdf_proxy preview) def show redirect_to attachment_url end def preview ga_track('preview') @resource = resource_download.resource RestClient.head(attachment_url) rescue RestClient::ExceptionWithResponse => e render text: e.response, status: '404' end def pdf_proxy uri = URI.parse attachment_url send_data uri.open.read, disposition: :inline, file_name: attachment_url.split('/').last, type: 'application/pdf' end private def attachment_url @attachment_url ||= download.attachment_url end def resource_download @resource_download ||= ResourceDownload.find(params[:id]) end def download @download ||= resource_download.download end def ga_track(category = nil) action = show_with_slug_path(params[:slug]) if params[:slug].present? ga_track_download(action: action, label: attachment_url, category: category) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems