因此,如果我制作了这样的表单,则在 HTML 中:
<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>
我希望params[:categories]
成为
[{"name"=>"value"},{"name"=>"value"},{"name"=>"value"},{"name"=>"value"}]
但相反,rails 2 将引发 TypeError: expected Hash (got Array) for param
错误在这里提出:
http://apidock.com/rails/Rack/Utils/normalize_params
为什么这在 Rails 中不允许或不可解析?我错过了什么?
我知道我可以像这样索引输入
<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]" />
并得到一个哈希。但这似乎适得其反。