Created
December 19, 2008 04:36
-
-
Save atnan/37888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example POST of multiple resources: | |
POST http://example.com/users? | |
users[0][first_name]=John | |
users[0][last_name]=Doe | |
users[1][first_name]=Jane | |
users[1][last_name]=Doe | |
===== | |
Current params output: | |
{ | |
:users => { | |
'0' => { | |
:first_name => 'John', | |
:last_name => 'Doe' | |
}, | |
'1' => { | |
:first_name => 'Jane', | |
:last_name => 'Doe' | |
} | |
} | |
} | |
Which forces me to do something like this: | |
params[:users] ||= [] | |
params[:users] = params[:users].values if params[:users].is_a?(Hash) | |
===== | |
Desired params output: | |
{ | |
:users => [ | |
{ | |
:first_name => 'John', | |
:last_name => 'Doe' | |
}, { | |
:first_name => 'Jane', | |
:last_name => 'Doe' | |
} | |
] | |
} | |
===== | |
# How it current works: | |
y ActionController::AbstractRequest.parse_query_parameters('users[][first_name]=1&users[][last_name]=1&users[][last_name]=2&users[][first_name]=3&users[][last_name]=3') | |
# How you can get around it: | |
workaround_params = 'users[0][first_name]=1&users[0][last_name]=1&users[1][last_name]=2&users[2][first_name]=3&users[2][last_name]=3' | |
y ActionController::AbstractRequest.parse_query_parameters(workaround_params) | |
# The ideal: | |
y ActionController::AbstractRequest.parse_query_parameters(workaround_params).map { |k,v| v.values } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment