Skip to content

Instantly share code, notes, and snippets.

@oeddyo
Created July 14, 2015 05:42
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 oeddyo/14450fbd2b6cd7bc99ad to your computer and use it in GitHub Desktop.
Save oeddyo/14450fbd2b6cd7bc99ad to your computer and use it in GitHub Desktop.
sdfa
post "/retailers/#{retailer_id}/orders",
{:order => {:retailer_id => retailer_id, :product_ids_with_quantities => [[2, 1],[2, 1]]}}.to_json,
{:Authorization => token}
打印params的话
{"order"=>{"retailer_id"=>"1", "product_ids_with_quantities"=>["2", "1", "2", "1"]}, "format"=>:json, "controller"=>"api/v1/orders", "action"=>"create", "retailer_id"=>"1"}
@oeddyo
Copy link
Author

oeddyo commented Jul 14, 2015

post "/retailers/#{retailer_id}/orders",
{:order => {:retailer_id => retailer_id, :product_ids_with_quantities => [[2, 1],[2, 1]]}},
{:Authorization => token}

gives
打印params的话
{"order"=>{"retailer_id"=>"1", "product_ids_with_quantities"=>["2", "1", "2", "1"]}, "format"=>:json, "controller"=>"api/v1/orders", "action"=>"create", "retailer_id"=>"1"}

@oeddyo
Copy link
Author

oeddyo commented Jul 14, 2015

  def raw_post(action, params, body, token)
    @request.env['RAW_POST_DATA'] = body
    puts params
    response = post action, params, {:Authorization => token}
    @request.env.delete('RAW_POST_DATA')
    response
  end

  raw_post "/retailers/#{retailer_id}/orders",
       {:order => {:retailer_id => retailer_id, :product_ids_with_quantities => [[2, 1],[2, 1]]}}.to_json,
           nil,
           token

变成
{"{"order":{"retailer_id":1,"product_ids_with_quantities":"=>{"2,1"=>{","=>{"2,1"=>{"}}"=>nil}}}}, "format"=>:json, "controller"=>"api/v1/orders", "action"=>"create", "retailer_id"=>"1"}

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