-
Notifications
You must be signed in to change notification settings - Fork 366
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
Added a fix for the value mapping of an array of objects #413
Conversation
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
Thanks! |
Hi there, I used the master branch in my Gemfile, however I am still experiencing the issue when submit the params like this:
i debugged around the same place of the pull request. As In my example, cur is Any suggestion? Thank you. |
Yeah I don't think this fixed it, here is a spec master...trevorrjohn:show-broken-spec
|
I am dealing with the same problem with version 6.1.0. Just updated a spec to include nested attributes to my params hash and it throws |
@oestrich @Jack12816 Do you know what we still face this problem after merged? |
@Uysim please open a new issue and/or PR with details if you have a fix. |
# this. | ||
if cur.is_a?(Array) && cur.first.is_a?(Hash) | ||
cur = cur.first | ||
param[:scope] << '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem anyone's having is here.
This line changes params
, so next time we use example { do_request }
, it is called with altered scope
. Causing line 32 to fail.
If we move these lines into a loop, we'll go deeper and deeper, ending up with as many []
-s as we had do_request
-s. E.g. props[pictures][][][id]
if we called do_request
inside a group for request twice
I would suggest changing the code in such way that if we want to do nested arrays in parameter
, we should use ''
there. Like so:
parameter :pictures, type: :array
parameter :id, scope: [:pictures, '']
I can do it, just need some kind of approval on it =)
Auto-adding []
for array scopes of course would be nice, but I can't see a good way of doing it right now (if you do, you are very welcome). I think it should be done somewhere in writers, though, not changing user-defined params.
Or we can just use plain old scope: 'pictures[]'
I would revert this PR, 'cause it seems to break work with any array parameters (see @jsmartt code in #462 )
- What is it good for
I stumbled over the version 5 to 6 upgrade issue (#398) and this is an approach to solve the issue.
- What I did
I debugged the
cur
property to be an array and thep[:name]
access resulted in anTypeError: no implicit conversion of String into Integer
. Now we detect this situation and pick the first object of the array. Furthermore we add an additional empty string to thescopes
array as an indicator. This results in parameter names like this:props[pictures][][id]
.- A picture of a cute animal (not mandatory but encouraged)