无法在.Rails4中将.xls注册为自定义MIME类型

mar*_*ins 4 mime-types ruby-on-rails-4

我已经更新了config/initializers/mime_types.rb并重新启动了服务器.

Mime::Type.register "application/vnd.sealed-xls", :xls
Run Code Online (Sandbox Code Playgroud)

我的控制器看起来像这样:

respond_to do |format|
  format.xls {  send_file(file_name, filename:  "dagsrapport.xls")  }
  format.html
end
Run Code Online (Sandbox Code Playgroud)

这是我在进行GET时得到的错误 /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 { ... } }
Run Code Online (Sandbox Code Playgroud)

我缺少什么提示?根据文档,我无法看到我做错了什么:http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads

小智 9

我所做的就是将xls注册为Mime类型 - 只需添加到config/initializers/mime_types.rb Mime::Type.register "application/xls", :xls 并重新启动服务器.希望它会有所帮助.