4

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?

Rômulo Ceccon
  • 10,081
  • 5
  • 39
  • 47

1 Answers1

5

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 }
Rômulo Ceccon
  • 10,081
  • 5
  • 39
  • 47