You don't even need the download controller action, you can just generate a download-friendly link like so:
attachment.rbdef download_url
S3 = AWS::S3.new.buckets[ 'bucket_name' ] # This can be done elsewhere as well,
# e.g config/environments/development.rb
url_options = {
expires_in: 60.minutes,
use_ssl: true,
response_content_disposition: "attachment; filename=\"#{file_name}\""
}
S3.objects[ self.path ].url_for( :read, url_options ).to_s
end
<%= link_to 'Download Avicii by Avicii', attachment.download_url %>
If you still wanted to keep your download action for some reason then just use this:
attachments_controller.rbdef download
redirect_to @attachment.download_url
end
Thanks to guilleva for his guidance.