Created
June 4, 2009 09:27
-
-
Save dejan/123536 to your computer and use it in GitHub Desktop.
Nesting params in Rails
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
>> params = {"line_items"=>[{"quantity"=>"1"}, {"quantity"=>"2"}]} | |
=> {"line_items"=>[{"quantity"=>"1"}, {"quantity"=>"2"}]} | |
>> query = CGI::unescape(params.to_query) | |
=> "line_items[][quantity]=1&line_items[][quantity]=2" | |
>> parsed_params = ActionController::AbstractRequest.parse_query_parameters(query) | |
=> {"line_items"=>[{"quantity"=>"1"}, {"quantity"=>"2"}]} | |
>> params == parsed_params | |
=> true |
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
>> params = {"line_items"=>[{"quantity"=>"1", "sales_taxes"=>["11", "12"]}, {"quantity"=>"2", "sales_taxes"=>["22", "23"]}]} | |
=> {"line_items"=>[{"sales_taxes"=>["11", "12"], "quantity"=>"1"}, {"sales_taxes"=>["22", "23"], "quantity"=>"2"}]} | |
>> query = CGI::unescape(params.to_query) | |
=> "line_items[][quantity]=1&line_items[][sales_taxes][]=11&line_items[][sales_taxes][]=12&line_items[][quantity]=2&line_items[][sales_taxes][]=22&line_items[][sales_taxes][]=23" | |
>> parsed_params = ActionController::AbstractRequest.parse_query_parameters(query) | |
=> {"line_items"=>[{"quantity"=>"1", "sales_taxes"=>[]}, {"quantity"=>"2", "sales_taxes"=>["12"]}, {"sales_taxes"=>["22"]}, {"sales_taxes"=>["23"]}]} | |
>> params == parsed_params | |
=> false # check out how much different they are |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment