Reputation: 1501
I created file upload using paperclip! File uploads as it is supposed to. Than I added file download method like this:
def download
sample = Sample.find(params[:id])
send_file upload.sample.path,
:filename => upload.sample_file_name,
:type => upload.sample_content_type,
:disposition => 'attachment'
flash[:notice] = "Your file has been downloaded"
end
But I cant figure out, what should I put in my show action so that I would be able to download the file?
I got as far as this:
<td><%= @sample.upload_file_name =%></td>
<%= link_to 'Download', :action => :download, :path =>@sample.upload.url, :type => @sample.upload_content_type %>
But it shows error : Couldn't find Sample with id=download
Can anyone help me?
Upvotes: 2
Views: 7478
Reputation: 2575
It looks like you have mismatch in your routes.
That is why, you have to:
Read this post for more advanced Download functionality: http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads
Upvotes: 0
Reputation: 8894
Assuming you set download named route properly, you can just say
<%= link_to 'Download', download_sample_path(@sample) %>
Upvotes: 0
Reputation: 5437
=link_to 'download', @sample.upload.path This is the easiest way))
Upvotes: 0
Reputation: 864
Think you need to change your link_to to send the :id (that's what the controller action is looking for with params[:id])
<%= link_to 'Download', :action => :download, :id => @sample.id %>
Soz Karlis was writing as you posted :D
Upvotes: 2