Offering downloads without giving away the cow

Nic Ollis
Nic Ollis
Feb 22, 2017 · 4 min read
resources :template, only [:show, :update] do
resources :download, only [:show] do
collection do
get ':id/pdf' => download#pdf, as: :pdf
get ':id/psd' => download#psd, as: :psd
end
end
end
def find_purchase
unless (@purchase = PurchaseRecord.find_by(key: param[:id])
flash[:error] = "Can't find purchase."
redirect_to template_path
end
end
def psd
authorize @purchase
send_template @purchase.psd_template.url, @purchase.psd_template_identifier
end
def send_template(url, filename)
data = open(url)
send_data data.read, filename: filename, disposition: 'inline', stream: 'true', buffer_size: '4096'
end
def fog_public
false
end

Program Practical

Easy to digest post to help make you a better programmer.

Nic Ollis

Written by

Nic Ollis

Software Engineer working out of Indiana

Program Practical

Easy to digest post to help make you a better programmer.