我正在将一个使用 Carrierwave 的应用程序移植到 Rails 4,但是我遇到了强参数的问题。我有一个模型
accepts_nested_attributes_for :photos
以下是上传图片的传递方式:
{
# ...
"model"=>
{
# ...
"photos_attributes"=>
{
"1362752177921"=>
{
"image"=>"test.jpg",
}
}
}
}
但是我似乎无法弄清楚如何编写接受的参数photos_attributes
。
我已经尝试过.permit(photos_attributes: [])
,但它只是跳过它们,当我使用 时permit!
,uuid
它是在保存之前创建的,不会出现在 SQL 中,这是第二个问题:
photos.uuid may not be NULL: INSERT INTO "photos" ("created_at", "model_id", "image", "title", "updated_at") VALUES (?, ?, ?, ?, ?)
这里缺少强参数的文档,我什至不知道如何进行。
更新 这适用于嵌套属性:
params.permit( ..., :photos_attributes => ['id', 'title', 'image', '_destroy'])
但看起来应该首先为 Rails 4 更新 Carrierwave 或 Nested Form。它只是试图一直保存一个空图像。相同的代码(没有 strong_params)适用于 Rails 3。