grape
grape copied to clipboard
declared(params) - "no implicit conversion of Symbol into Integer" when receiving blank array
- I have an optional array parameter. In some cases I want it to be blank, but if the items are passed, they must match the schema inside.
params do
optional :outline, type: Array do
requires :x
requires :y
end
end
- I do a PATCH request and send
{"outline": []}payload. - Received
params =>{ "outline"=>[""]} - here is the first question - why an empty string inside an array? I have a feeling that I've struggled with that a few years back, but don't remember what was the cause. declared(params)raisesno implicit conversion of Symbol into Integer
What content-type are you using? This should work with content-type: JSON, but if you supply things in multipart or query params Rack can't figure it out.
@dblock thanks for a quick response.
Content-type is JSON.
module API
class Base < Grape::API
prefix :api
content_type :json, 'application/json; charset=utf-8'
format :json
formatter :json, Grape::Formatter::ActiveModelSerializers
...
end
That defines the response, not the request. How do you PATCH/POST data?