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 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.