Rails send_data return HTTP error 406
download, http, ruby, ruby-on-rails, xls
Solution
Since you are using `format.xls`, you have to append `.xls` to the url. Try
curl -v https://localhost:3000/subscribes/export.xls
Otherwise, you can move `send_data` out of the `respond_to` block.
Problem
I have a little problem on an export as XLS from my database. I use the gem `to_xls` and after folowing the documentation I have this error that I don't know how to get ride of and launch the download of my file: controller: ``` def export @subscribes = Subscribe.all respond_to do |format | format.xls { send_data@subscribes.to_xls, disposition: 'attachment', : filename = > 'Subscribes.xls' } end end ``` My MIME file ``` Mime::Type.register "application/vnd.ms-excel", :xls ``` And so, the error that I got with the full header: ``` Request URL:https://localhost:3000/subscribes/export Request Method:GET Status Code:406 Not Acceptable Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding:gzip,deflate,sdch Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 Connection:keep-alive Host:localhost:3000 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 Cache-Control:no-cache Connection:close Content-Type:text/html; charset=utf-8 Server:thin 1.5.1 codename Straight Razor Strict-Transport-Security:max-age=31536000 X-Request-Id:a5be7889994f1035818d6a554f991636 X-Runtime:0.012001 X-UA-Compatible:IE=Edge ``` Thanks for helping me :)