-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to allow empty array for params? #1370
Comments
If you're POSTing JSON, I believe this just works. Care to share the code that does the POSTing? I'll close this. Please use the Grape mailing list for questions. |
I have the same problem, and can't figure out what a possible solution could be. It just seems a buggy behaviour. I need to allow the user to publish an article, and optionally specify a section. I also need to accept an empty array, that will result in unpublishing the article from the specified domain. The non-working code is the following: desc 'Publish an article'
params do
optional :published_in, type: Hash do
optional :'foo.com', type: Array[String], values: ALLOWED_SECTIONS['foo'], allow_blank: true
optional :'bar.com', type: Array[String], values: ALLOWED_SECTIONS['bar'], allow_blank: true
end
end
post 'articles/123/actions/publish' do
# ...
end But if I omit the desc 'Publish an article'
params do
optional :published_in, type: Hash do
optional :'foo.com', type: Array[String], allow_blank: true
optional :'bar.com', type: Array[String], allow_blank: true
end
end
post 'articles/123/actions/publish' do
# ...
end I'd like to specify the allowed values in the params block. Any suggestion? |
What is the posting code? What is the error? What content-type is it POSting @liquid1982 ? |
@dblock It is something like: $.ajax({
url: url,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload)
}).then(() => {}) and the error message is |
You should turn it into a spec @liquid1982 in this project. |
I wrote the following code.
A request with following params succeeds
{ items: [{ id: 1, enabled: true }, { id: 2, enabled: false }] }
But fails with following.
{ items: [] }
I changed the code to
But, all requests failed then.
I want to allow
{ items: [] }
params. Is there any way to do it?Thanks.
The text was updated successfully, but these errors were encountered: