Reputation: 11
Please tell me how this works, because I don't understand... Here is my simple code:
Route:
get 'download' =>'pages#download'
My action:
def download
send_file "#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip"
And download link:
<%= link_to "download", download_path %>
So, when i'm clicking on the link I get this:
Image http://joxi.ru/GrqvQ3xHlbaYmz.jpg
It seems like the browser is trying to show zip file content... But when I open the action from my browser (or refresh page) it's working fine.
Why doesn't it work when I click on the link generated by link_to
?
Upvotes: 1
Views: 2400
Reputation: 115
Adding disposition: "inline"
instead of disposition: "attachment"
worked for me.
Upvotes: 4
Reputation: 3449
Send_file open file in browse instead of download it
Try with this
def download
send_file("#{Rails.root}/public/downloads/robots.zip", :type=>"application/zip",:disposition=> "attachment; filename=robots.zip")
end
and
<%= link_to "download", download_path ,target: '_self' , data-turbolinks="false" %>
Upvotes: 1