So in HTML if I made a form like this:
<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 params[:categories]
to be
[{"name"=>"value"},{"name"=>"value"},{"name"=>"value"},{"name"=>"value"}]
But instead, rails 2 will raise a TypeError: expected Hash (got Array) for param
The error is raised here:
http://apidock.com/rails/Rack/Utils/normalize_params
Why is this not allowed or not parseable in rails? What am I missing?
I know I could index the input like so
<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 a Hash. But this seems counter-productive.
You've got to reverse the subscript order:
<input type="text" name="categories[name][]" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With