在Rails中覆盖MIME类型 [英] Overriding a MIME type in Rails

查看:71
本文介绍了在Rails中覆盖MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Rails中的JSON MIME类型("application/json")覆盖为("text/x-json").我试图再次在mime_types.rb中注册MIME类型,但这没有用.有什么建议吗?

I want to override the JSON MIME type ("application/json") in Rails to ("text/x-json"). I tried to register the MIME type again in mime_types.rb but that didn't work. Any suggestions?

谢谢.

推荐答案

这应该有效(在初始化程序,插件或类似的地方):

This should work (in an initializer, plugin, or some similar place):

Mime.send(:remove_const, :JSON)
Mime::Type.register "text/x-json", :json

这篇关于在Rails中覆盖MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆