Search code examples
htmlruby-on-railsdownloadhreftext-files

Text file download link (ruby on rails)


I want to add a download link to my html page. Download will be a .txt file. I have done this,

<a href="path_to_file/myfile.txt">click to download txt </a>

But the problem is, when a user clicks this link, instead of asking user to download the file, it simply shows the text in the browser.

How can I change this script to ask user to download the file (with the default download prompt dialog box)

UPDATE: Thanks all for the replies. I'm using ruby/rails on the server side.


Solution

  • Use rails send_file method