sinatra-param icon indicating copy to clipboard operation
sinatra-param copied to clipboard

Boolean type parameter not working

Open ricardovsilva opened this issue 6 years ago • 1 comments

If I try

patch '/:id' do |id|
    content_type :json
    param :foo, Boolean, required: true
  end

And try to do a patch passing as body:

{
  "foo": true
}

It raises 400 error. Am I doing anything wrong?

ricardovsilva avatar May 17 '18 18:05 ricardovsilva

It doesn't decode JSON by default. Just query parameters and application/x-www-form-urlencoded in body.

From the README:

Use sinatra-param in combination with Rack::PostBodyContentTypeParser and Rack::NestedParams to automatically parameterize JSON POST bodies and nested parameters.

Sorry, I haven't tried that. There is another Issue asking for particulars. https://github.com/mattt/sinatra-param/issues/89

You should go visit the documentation for Rack::PostBodyContentTypeParser and Rack::NestedParams.

I gather that Rack::PostBodyContentTypeParser reads JSON body and adds to params.

jtara avatar Aug 28 '18 18:08 jtara