加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-4 – 无法在.Rails4中将.xls注册为自定义MIME类型

发布时间:2020-12-17 02:47:37 所属栏目:百科 来源:网络整理
导读:我已经更新了config / initializers / mime_types.rb并重新启动了服务器. Mime::Type.register "application/vnd.sealed-xls",:xls 我的控制器看起来像这样: respond_to do |format| format.xls { send_file(file_name,filename: "dagsrapport.xls") } form
我已经更新了config / initializers / mime_types.rb并重新启动了服务器.

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

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

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

这是我在/sheet.xls上进行GET时得到的错误

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 { ... } }

我缺少什么提示?根据doc:http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads,我看不出我做错了什么

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读