likitung
likitung

Reputation: 11

Send_file open file in browse instead of download it

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

Answers (2)

Max Kaplan
Max Kaplan

Reputation: 115

Adding disposition: "inline" instead of disposition: "attachment" worked for me.

Upvotes: 4

Mayur Shah
Mayur Shah

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

Related Questions