覆盖Rails中的MIME类型

时间:2008-09-18 18:44:56

标签: ruby-on-rails ruby json mime mime-types

我想在Rails中覆盖JSON MIME类型(“application / json”)(“text / x-json”)。我试图在mime_types.rb中再次注册MIME类型,但这不起作用。有什么建议吗?

感谢。

2 个答案:

答案 0 :(得分:11)

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

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

答案 1 :(得分:3)

尝试:

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