我一直在使用strong_parameters gem与Rails 3.2相当长一段时间。到目前为止,一切都很好。如何在rails 3.2上的strong_parameters更新之后更新嵌套对象?
将strong_parameters最近更新为v0.2.0之后,我不再可以更新嵌套对象。
这里是请求参数
{
"resource"=>{
"name"=>"1362483207-11-offer",
"slug"=>"1362483207-11-offer",
"code"=>"136248320711",
"category_id"=>"4",
"price"=>"100",
"short_description"=>"",
"description"=>"",
"offer_card_types_attributes"=>{
"0"=>{"id"=>"11", "card_type_id"=>"1"},
"1"=>{"card_type_id"=>"0"},
"2"=>{"card_type_id"=>"0"},
"3"=>{"card_type_id"=>"0"}
},
"show_banner"=>"1",
"autoclaim"=>"1",
"published"=>"0",
"number_of_codes_to_generate"=>"",
"images_attributes"=>{
"0"=>{"retained_image"=>"", "_destroy"=>"true", "id"=>"1"},
"on-1362560061857"=>{
"image"=>#<ActionDispatch::Http::UploadedFile:0x0000080ef654f8 ... >
}
},
"partner_id"=>"2",
"all_checkout_places"=>"0",
"offer_checkout_places_attributes"=>{
"0"=>{"checkout_place_id"=>"0"},
"1"=>{"id"=>"11", "checkout_place_id"=>"7"},
"2"=>{"checkout_place_id"=>"0"},
"3"=>{"checkout_place_id"=>"0"},
"4"=>{"checkout_place_id"=>"0"}
}
},
"id"=>"11"
}
我已经试过这PARAMS而params这一点。我只是不更新嵌套的对象。 请帮忙
起初我以为params.require(:resource).permti(..., :images => [])
应该做的伎俩,但它失败了,然后我尝试了其他各种选择。他们都失败了。
我如何允许所有这些嵌套的对象。
你可以把你的模型代码?它可能是一个大规模分配问题(attr_accessible) – rorra 2013-03-06 09:49:52
attr_accessible不是问题。其实我不用它 '''config.active_record.whitelist_attributes = false''' – graudeejs 2013-03-06 10:51:33