-
Notifications
You must be signed in to change notification settings - Fork 167
File upload with Strong Parameters #114
Comments
Perhaps your |
It's just a key in params hash, besides what now, I can't upload files anymore? |
have you tried |
The |
@fxn Yes, I expect an array of hashes with nested values for photos. So can I whitelist it? And the other question is how can I make to save the @rafaelfranca Yes, that is what I've tried, params return this then:
But it skips the hash inside. |
I cannot try now, but if my memory is not wrong (rare, but sometimes it happens!) I believe you can declare the atributes as if they were direct children. Strong parameters special-cases hashes whose keys are integers. |
In fact this worked, thanks!
|
@senny maybe we could add it to the "more examples" section? |
@fxn I'll add an example for hashes with integer keys! |
I added the example: https://github.com/lifo/docrails/commit/1d8b56647859fc0c66149642d83b29e3118d2cb0 |
Fantastic Yves! |
This replicates the situation described in rails/strong_parameters#114
I am porting an application that uses Carrierwave to Rails 4, but I have problems with strong params. I have a model with
Here is how CW passes uploaded images:
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 everything inside the photo params hash (image
,title
,_destroy
) . When I usepermit!
, it might almost work, but first of all this is kinda lame. And then theuuid
that is created inside the model before saving doesn't appear in SQL on save and this is the second issue:Documentation is seriously lacking here and I am not even sure how to proceed.
How to accept an array of nested parameters? How to add additional parameters for nested models when saving?
The text was updated successfully, but these errors were encountered: