ruby-on-railssendfile

send_file just sends an empty file


Im looking for a way to download a xml file. I use:

file_path = 'folder/' + xml_name + '.xml'
send_file file_path, :type => "text/xml"

but this always downloads me an empty file. The file itself has 16 KB of data in it...

why is that?

Maechi


Solution

  • Problem saved, but I don't know why

    File.open(file_path, 'r') do |f|
      send_data f.read, :type => "text/xml", :filename => "10.xml"
    end
    

    send_data is working... but send_file not!