[英]Rails 4 Strong parameters, permit parameters for multiple models
My params hash has attributes for multiple models which are all part of a collection and records must be created and tied to each other. 我的params散列具有多个模型的属性,这些属性都是集合的一部分,必须创建记录并将它们相互关联。 eg 例如
Model Collection
has Physical Items
has Logical Items (takes nested attributes for logical items)
has Locations
etc...
So even though my params hash is being posted to Collection Controller, it looks like 因此,即使我的params hash被发布到Collection Controller,它看起来也像
Parameters: {"collection"=>{"client_id"=>"1",...and other collection params, "logical_items_attributes"=>{"0"=>{"logical_item"=>"", ... other logical items attributes.}}, "item_1"=>{"item_type_id"=>"1",...},"other_loose_param_1"=>"loose_param_value".. etc..., "commit"=>"Save"}
All these attributes must be permitted as all the records must be created as a single transaction and must be tied to each other. 必须允许所有这些属性,因为所有记录必须作为单个事务创建,并且必须彼此绑定。 How can I get through strong parameters? 如何获得强参数?
以下是答案。
params.permit!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.