Rails 2 - expected hash (received array) for parameter

So, in HTML, if I made this form:

<form method="post">
<input type="text" name="categories[][name]" />
<input type="text" name="categories[][name]" />
<input type="text" name="categories[][name]" />
<input type="text" name="categories[][name]" />
<input type="submit" value="submit" />
</form>

I expect to params[:categories]be

[{"name"=>"value"},{"name"=>"value"},{"name"=>"value"},{"name"=>"value"}]

But instead, rails 2 will raise a TypeError: the expected Hash (received array) for param

Here an error occurs:

http://apidock.com/rails/Rack/Utils/normalize_params

Why is this not permitted or not handled on rails? What am I missing?

I know that I could index the input like this:

<input type="text" name="categories[0][name]" />
<input type="text" name="categories[1][name]" />
<input type="text" name="categories[2][name]" />
<input type="text" name="categories[3][name]" />

And get the hash. But that seems counterproductive.

+5
source share
1 answer

You need to reverse the order of the substring:

<input type="text" name="categories[name][]" />
+3
source

All Articles