Skip to content

Instantly share code, notes, and snippets.

@Agowan
Created June 3, 2015 08:48
Show Gist options
  • Save Agowan/12ced613d1d316244d16 to your computer and use it in GitHub Desktop.
Save Agowan/12ced613d1d316244d16 to your computer and use it in GitHub Desktop.
Renaming files on response for expiring url.
# encoding: UTF-8
class Report < ActiveRecord::Base
has_attached_file :file, :path => "/:statistic_report_root/:year/:id_partition.pdf"
end
class ReportsController < ApplicationController
def download
report = Report.find(params[:id])
options = {expires: 100, :response_content_type => "application/vnd.ms-excel", response_content_disposition: "'attachment; filename=test.xls'"}
redirect_to report.pdf.s3_object.url_for(:read, options).to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment