Rails 3 has a nice feature where it will parse the body of PUT and POST requests depending on the Content-type given. So for example, if I POST XML to Rails, it will all be decoded for me and put into the params hash.

Well, it’s a nice feature until you try to switch it off, it’s a nightmare to disable! I managed it in the end, here’s what I did…

I created a piece of ‘rack middleware’ that overwrites the Content-Type for given paths:

# lib/no_parse.rb
class NoParse
  def initialize(app, options={})
    @app = app
    @urls = options[:urls]

  def call(env)
    env['CONTENT_TYPE'] = 'text/plain' if @urls.include? env['PATH_INFO']

Included it:

require_relative '../lib/no_parse'

Added it into the ‘stack’:


# (Change the :urls to specify which paths use NoParse.)
                                             'NoParse', :urls => ['/example-path'])

Make sure you restart rails, and you should be good to go. If it’s not working, make sure the rake middleware command is listing the NoParse class above ActionDispatch::ParamsParser.

Cheers, Dave.