在params中允许数组

我有以下JSON:

{ "name": "pizza", "ingredients": [ {"name": "tomato", "amount": 3, "unit": "un"}, {"name": "chesse", "amount": 100, "unit": "gr"} ] } 

我使用POST将这个JSON传递给我的控制器,然后我需要相信这个参数,但我不能允许散列ingredients数组。

怎么允许呢? 我尝试了params.permit(:ingredients).permit(:name, :amount, :unit).to_h ,但它不起作用。

params.permit(:name, :ingredients => [:name, :amount,:unit])应该可以解决问题。

读取嵌套参数 。