本文介绍了如何在 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 中允许带有散列的数组?
发布评论