问题
My application defines a custom Mime type for its Rest interface. So I register it in the mime_types.rb initializer:
Mime::Type.register "application/vnd.example.app-v1+xml", :xml_v1
and Rails correctly handles the respond_to blocks in the controllers.
However, I still need to tell Rails that incoming requests should be parsed as an XML, using ActionDispatch::ParamsParser. I just don't know how to use it inside an initializer. What's the correct way?
回答1:
This works well:
Mime::Type.register "application/vnd.example.app-v1+xml", :xml_v1
MyRailsApp::Application.config.middleware.delete "ActionDispatch::ParamsParser"
MyRailsApp::Application.config.middleware.use ActionDispatch::ParamsParser, { Mime::XML_V1 => :xml_simple }
来源:https://stackoverflow.com/questions/7556150/how-do-i-initialize-actiondispatchparamsparser-in-rails-3-1