Overriding a MIME type in Rails

一笑奈何 提交于 2019-12-10 21:20:37

问题


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?

Thanks.


回答1:


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

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



回答2:


Try:

render :json => var_containing_my_json, :content_type => 'text/x-json'


来源:https://stackoverflow.com/questions/95554/overriding-a-mime-type-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!