如何在 Rails 4 中允许带有散列的数组?

编程入门 行业动态 更新时间:2024-10-26 21:25:41
本文介绍了如何在 Rails 4 中允许带有散列的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Rails 4 中有以下参数:

There is the following params in Rails 4:

{"delivery_time":"10","delivery_type_id":"1","order_items":[{"count":"5","item_id":"1"}],"order_status_id":"1","user_id":"1","action":"create","controller":"api/v1/orders"}

有以下强参数:

params.permit(:user_id, :order_status_id, :delivery_type_id, :delivery_time, order_items:[])

但是此代码返回没有 'order_items' 数组的哈希值.我认为原因是数组中的散列.请告诉我,我该如何解决?提前致谢

But this code returns hash without 'order_items' array. I think the reason is hash in array. Please, tell me, how can I fix it? Thanks in advance

推荐答案

您可以包含嵌套数组,例如:

You can include nesting arrays, for your example it would be:

params.permit(:user_id, :order_status_id, :delivery_type_id, :delivery_time, order_items: [:count, :item_id])

其他人可以在这里找到更多信息 - edgeapi.rubyonrails/classes/ActionController/StrongParameters.html

Others can find out more here - edgeapi.rubyonrails/classes/ActionController/StrongParameters.html

更多推荐

如何在 Rails 4 中允许带有散列的数组?

本文发布于:2023-10-24 15:00:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   如何在   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!