I have a condition where i need to pass a parameter as an array of hashes which looks like this:
The following is the Rack::Test post method for API call.
post "#{url}.json",
:api_key => application.key,
:data => [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}],
:run => { :title => "The First Run" }
And this is the log of the rails app.
Parameters: {"api_key"=>"6a9acb84d0ea625be75e70a1e04d26360606ca5b", "data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}], "run"=>{"title"=>"The First Run"}, "line_id"=>"4e018e2c55112729bd00000a"}
Now, this is the RestClient post method I'm using to call the API.
RestClient.post("/lines/#{@line.id}/runs.json", {:run => {:title => @title}, @param_for_input => @param_data})
And this is the log of the rails app.
Parameters: {"run"=>{"title"=>"run name"}, "data"=>{"Company"=>"Google", "Website"=>"google.com"}, "api_key"=>"f488a62d0307e79ec4f1e6131fa220be47e83d44", "line_id"=>"4e018a505511271f82000144"}
The difference is in the data
parameter.
When sending with Rack::Test method, the data is passed as "data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}]
but via RestClient way, the parameter data array is stripped out and only the last hash is passed as "data"=>{"Company"=>"Google", "Website"=>"google.com"}
Why the RestClient is stripping out the array of hashes to just a last hash of the array?
@param_data
is what you think it is? I'm using RestClient and haven't seen any issues like this. – Twospot@param_data = [{:Company => "Google", :Website => "google.com"}, {:Company => "Times", :Website => "times.com"}]
– Isochroous