Sean Huber is right, and the code in the question is correct. Except in cases of registration of the MIME type and subsequent playback of files of this type, for example,
Mime::Type.register('application/foobar', :foobar) render('view')
In this case, the registered type string always overrides the approaches available to set the content type explicitly. This may lead to the idea that the media type parameters are erased, because, by coincidence, the ParamsParser choice seems to break when the media type parameters are set for the parser by default, that is, the analyzer registered for "application / foo"; bar = 1 'will not analyze the content provided by this type of content, forcing to use a string with no parameters for a string of type mime, and then try to redefine it with one parameter.
So, to get around this in 4.2, I unregistered ParamsParser and Render and went to the before_filter file on the parent controller and the content type header in after_filter, e.g.
class BaseController < ApplicationController before_filter :parse_body after_filter :set_content_type attr_accessor :parsed def parse_body self.parsed = JSON.load(request.body) end def set_content_type self.content_type = "application/foo; bar=1; charset=utf-8" end end
Note: this is a pretty hack / workaround; not recommended for long term use.
source share