I am using Ruby on Rails 4.1 and I would like to know some more about "indexes" added to parameters when incoming data contains array of hashes.
That is, for instance, when I run the following code (as an example, the code executes a simple AJAX request to my application)
var my_data = [
{ "a1": 1, "b1": 2 },
{ "a2": 1, "b2": 2 },
{ "a3": 1, "b3": 2 },
];
$.ajax({
type: "POST",
url: "http://0.0.0.0:3000/path.json",
data: { "my_data": my_data }
});
Then Rails parses the following parameters by "automagically" adding "0"
, "1"
, "2"
indexes:
{"my_data"=>{"0"=>{"a1"=>"1", "b1"=>"2"}, {"1"=>{"a2"=>"1", "b2"=>"2"}, {"2"=>{"a3"=>"1", "b3"=>"2"}}
- Why Rails adds those indexes?
- When Rails is supposed to add indexes? And when not?
- How to avoid Rails to add indexes?