send_file in rails does not download to browser - instead loads in browser window directly

Viewed 4722

I have the following in my .erb:

<%= link_to 'Download PDF', planners_download_pdf_url %>

I have the following method to respond:

  def download_pdf
  send_file(
     "#{Rails.root}/Thing/ex/example.xls",
filename: "mything.xls",
type: "application/xls"
  )
  end

My routes has:

get '/planners/download_pdf'

When I click my link, the method does get invoked. My problem is that is doesn't download to the browser. Instead, it takes the tab I have open in the browser and dumps the file as HTML. Like... have you ever seen an Excel file opened in notepad? It does that. See below:

Garbage

How do I get this to instead download the file?

1 Answers
Related