I am porting an application that uses Carrierwave to Rails 4, but I have problems with strong params. I have a model with
accepts_nested_attributes_for :photos
Here is how uploaded images are passed:
{
# ...
"model"=>
{
# ...
"photos_attributes"=>
{
"1362752177921"=>
{
"image"=>"test.jpg",
}
}
}
}
However I can't seem to figure out how to write parameters that will accept photos_attributes
.
I have tried .permit(photos_attributes: [])
but it simply skips them, when I use permit!
, uuid
that is created before saving doesn't appear in SQL and this is the second issue:
photos.uuid may not be NULL: INSERT INTO "photos" ("created_at", "model_id", "image", "title", "updated_at") VALUES (?, ?, ?, ?, ?)
Documentation for strong parameters is lacking here and I am not even sure how to proceed.
Update This worked with the nested attributes:
params.permit( ..., :photos_attributes => ['id', 'title', 'image', '_destroy'])
But looks like either Carrierwave or Nested Form should be updated for Rails 4 first. It simply tries to save an empty image all the time. Same code (without strong_params) works in Rails 3.
This worked with the nested attributes:
params.permit( ..., :photos_attributes => ['id', 'title', 'image', '_destroy'])
But looks like either Carrierwave or Nested Form should be updated for Rails 4 first. It simply tries to save an empty image all the time which I kinda eliminated with :reject_if
, but still it is not 100 working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With