Skip to content

Instantly share code, notes, and snippets.

@joshleaves
Created April 14, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshleaves/24b545e7aec87328408facb3b399bc29 to your computer and use it in GitHub Desktop.
Save joshleaves/24b545e7aec87328408facb3b399bc29 to your computer and use it in GitHub Desktop.
Rails is fucking up HTTP
2.2.0 :001 > opts = {
2.2.0 :002 > body: {
2.2.0 :003 > references: [
2.2.0 :004 > { item_id: 1, item_type: 'Part', code: 'IP5-SCREEN', gem_code: '1-UPTO-13' },
2.2.0 :005 > { item_id: 1, item_type: 'Accessory', code: 'SELFIE-FU', gem_code: '13-NUMBERS' }
2.2.0 :006?> ]
2.2.0 :007?> }
2.2.0 :008?> }
=> {:body=>{:references=>[{:item_id=>1, :item_type=>"Part", :code=>"IP5-SCREEN", :gem_code=>"1-UPTO-13"}, {:item_id=>1, :item_type=>"Accessory", :code=>"SELFIE-FU", :gem_code=>"13-NUMBERS"}]}}
2.2.0 :009 > opts.to_query
=> "body%5Breferences%5D%5B%5D%5Bcode%5D=IP5-SCREEN&body%5Breferences%5D%5B%5D%5Bgem_code%5D=1-UPTO-13&body%5Breferences%5D%5B%5D%5Bitem_id%5D=1&body%5Breferences%5D%5B%5D%5Bitem_type%5D=Part&body%5Breferences%5D%5B%5D%5Bcode%5D=SELFIE-FU&body%5Breferences%5D%5B%5D%5Bgem_code%5D=13-NUMBERS&body%5Breferences%5D%5B%5D%5Bitem_id%5D=1&body%5Breferences%5D%5B%5D%5Bitem_type%5D=Accessory"
2.2.0 :010 > opts[:body].to_query
=> "references%5B%5D%5Bcode%5D=IP5-SCREEN&references%5B%5D%5Bgem_code%5D=1-UPTO-13&references%5B%5D%5Bitem_id%5D=1&references%5B%5D%5Bitem_type%5D=Part&references%5B%5D%5Bcode%5D=SELFIE-FU&references%5B%5D%5Bgem_code%5D=13-NUMBERS&references%5B%5D%5Bitem_id%5D=1&references%5B%5D%5Bitem_type%5D=Accessory"
2.2.0 :011 > Rack::Utils.parse_nested_query(_)
=> {"references"=>[{"code"=>"IP5-SCREEN", "gem_code"=>"1-UPTO-13", "item_id"=>"1", "item_type"=>"Part"}, {"code"=>"SELFIE-FU", "gem_code"=>"13-NUMBERS", "item_id"=>"1", "item_type"=>"Accessory"}]}
2.2.0 :012 > opts[:body].to_query.split('&').sort.join('&')
=> "references%5B%5D%5Bcode%5D=IP5-SCREEN&references%5B%5D%5Bcode%5D=SELFIE-FU&references%5B%5D%5Bgem_code%5D=1-UPTO-13&references%5B%5D%5Bgem_code%5D=13-NUMBERS&references%5B%5D%5Bitem_id%5D=1&references%5B%5D%5Bitem_id%5D=1&references%5B%5D%5Bitem_type%5D=Accessory&references%5B%5D%5Bitem_type%5D=Part"
2.2.0 :013 > Rack::Utils.parse_nested_query(_)
=> {"references"=>[{"code"=>"IP5-SCREEN"}, {"code"=>"SELFIE-FU", "gem_code"=>"1-UPTO-13"}, {"gem_code"=>"13-NUMBERS", "item_id"=>"1"}, {"item_id"=>"1", "item_type"=>"Accessory"}, {"item_type"=>"Part"}]}
2.2.0 :014 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment