Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to register .xls as custom MIME type in Rails4

I've updated config/initializers/mime_types.rb and restarted the server.

Mime::Type.register "application/vnd.sealed-xls", :xls

My controller looks like this:

respond_to do |format|
  format.xls {  send_file(file_name, filename:  "dagsrapport.xls")  }
  format.html
end

This is the error I get when I do a GET on /sheet.xls

To respond to a custom format, register it as a MIME type first: 
http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. If you meant to 
respond to a variant like :tablet or :phone, not a custom format, be sure to nest your variant 
response within a format response: format.html { |html| html.tablet { ... } }

Any tips to what I'm missing? I can't see what I'm doing wrong according to the doc: http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads

like image 734
martins Avatar asked Sep 09 '14 07:09

martins


1 Answers

All I did to register xls as Mime type - just added to config/initializers/mime_types.rb Mime::Type.register "application/xls", :xls and restarted the server. Hope it'll help.

like image 160
AlexanderF Avatar answered Oct 21 '22 16:10

AlexanderF