0

I'm running Rails 5.0.0.1, and have a controller called Voice::NumbersController, accessible by a route like:

  scope '/api' do
    namespace :v1 do
      namespace :voice do
        resources :numbers
      end
    end
  end

I want to have an optional parameter "number". For some reason, a GET request to /api/v1/voice/numbers with no params gets params[:numbers] passed to it when I have Content-Type: application/json in the request.

Is this because a GET with a body confuses things? If I put some content in the body (i.e. "hello": 5), I get the following:

  Parameters: {"_json"=>"hello: 5", "number"=>{"_json"=>"hello: 5"}}

This doesn't make much sense to me - it seems reasonable that "_json" is set, but not "number".

Is there a way to disable this automatic inclusion of the "number" param?

1 Answers1

3

This is parameter wrapping.

I believe you can disable it in config/initializers/wrap_parameters.rb as follows:

ActiveSupport.on_load(:action_controller) do
  wrap_parameters format: []
end

You can also disable it on a per-controller basis:

class Voice::NumbersController < ApplicationController
  wrap_parameters false
  # ...
end
Steve
  • 5,398
  • 2
  • 38
  • 39