Skip to content

support Array with index#1261

Open
itoufo wants to merge 1 commit into
ruby-grape:masterfrom
itoufo:master
Open

support Array with index#1261
itoufo wants to merge 1 commit into
ruby-grape:masterfrom
itoufo:master

Conversation

@itoufo
Copy link
Copy Markdown

@itoufo itoufo commented Jan 30, 2016

This change will enable to use array with index.

params do
  requires :abc, type: Array do
    requires :name
  end
end
<input type="text" name="abc[0][name]]"> 
<input type="text" name="abc[1][name]">

Comment thread lib/grape/util/hash_parameter.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false unless hash.present?

@dblock
Copy link
Copy Markdown
Member

dblock commented Feb 1, 2016

I like this. It needs to be documented in README, updated in CHANGELOG, commits squashed, please.

Comment thread CHANGELOG.md
* [#1252](https://github.com/ruby-grape/grape/pull/1252): Allow default to be a subset or equal to allowed values without raising IncompatibleOptionValues - [@jeradphelps](https://github.com/jeradphelps).
* [#1255](https://github.com/ruby-grape/grape/pull/1255): Allow param type definition in `route_param` - [@namusyaka](https://github.com/namusyaka).
* [#1257](https://github.com/ruby-grape/grape/pull/1257): Allow Proc, Symbol or String in `rescue_from with: ...` - [@namusyaka](https://github.com/namusyaka).
* [#1261](https://github.com/ruby-grape/grape/pull/1261): support array with index - [@itoufo](https://github.com/itoufo).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support with a capital S please.

@dblock
Copy link
Copy Markdown
Member

dblock commented Apr 1, 2016

I missed this PR, Github doesn't notify on force push. Can you please rebase it, make sure it passes and what not. I'll re-read the code now. Tack a comment here.

Comment thread README.md
end
```

If type is Array, It support following kinds of parameter.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never use curl in examples here, I don't think it's a good idea to introduce it. It's also fairly confusing TBH given that you POST to a JSON API, but don't actually send JSON data. I would explain this in Ruby, keeping it more like "documentation" and less like "example"?

@dja
Copy link
Copy Markdown

dja commented Aug 30, 2017

@dblock Can we get this branch updated and merged in? I'm running into this very issue where JQuery Ajax POSTs arrays with nested objects as hashes 0-based keys.. 😒

@dblock
Copy link
Copy Markdown
Member

dblock commented Aug 30, 2017

Please see my comments above and feel free to finish the PR @dja.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants