Rails中的MIME类型错误

来源:互联网 发布:淘宝便携自行车 编辑:程序博客网 时间:2024/06/05 21:42

什么是MIME?

MIME(Multipurpose Internet Mail
Extensions)多用途互联网邮件扩展类型,是来设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开

问题记录:
在用’axlsx_rails’ gem包做excel(文件后缀.xlsx)导出的时候,出现MIME没有初始化的错误

请求href: http://my_domain/export/export_file.xlsx

在export_controller.rb中

respond_to do |format|  format.xlsx {response.headers['Content-Disposition'] = "attachment; filename=#{filename}.xlsx"} end 

解决方式:

# config/initializers/mime_types.rb# Be sure to restart your server when you modify this file.# Add new mime types for use in respond_to blocks:# Mime::Type.register "text/richtext", :rtfMime::Type.register "application/xlsx", :xlsx
原创粉丝点击